0
点赞
收藏
分享

微信扫一扫

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)

云竹文斋 2022-02-22 阅读 110


其他语言输入输出见链接

1.输入两个数,输入数据包括多组。

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_牛客网

while True:
try:
a = list(map(int,input().split()))
print(a[0]+a[1])
except:
break
while True:
try:
a,b=map(int,input().strip().split())
print(a+b)
except EOFError:
break

2.第一行为一个整数,告诉你有几组数据,剩下的行是每组的数据

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_python_02

t = int(input())
for i in range(t):
a, b = list(map(int, input().split()))
print(a+b)

 3.输入数据有多组, 如果输入为0 0则结束输入

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_python_03

while True:
a, b = map(int, input().split())
if a == 0 and b == 0:
break
print(a + b)

 4.多组数据,每一行第一个数字代表这一组共有几个数据。当行中第一个数字为0时结束。

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_字符串_04

while True:
data=list(map(int,input().strip().split()))
n,array=data[0],data[1:]
if n==0:
break
print(sum(array))

 5.第一行的整数表示一共几组数据,剩下的行每一行第一个数字代表这一组共有几个数据

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_数据_05

tcase=int(input().strip())
for case in range(tcase):
data=list(map(int,input().strip().split()))
n,array=data[0],data[1:]
print(sum(array))

 6.多组数据,但是不知道多少组。每一行第一个数字代表这一组共有几个数据。

 python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_数据_06

 7.多组数据,但是不知道有多少组,每一组的数据个数也不一样。

 python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_字符串_07

while True:
try:
data=list(map(int,input().strip().split()))
print(sum(data))
except EOFError:
break

 8. 输入有两行,第一行n 。第二行是n个空格隔开的字符串,进行排序

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_数据_08

n=int(input())
words=[x for x in input().strip().split()]
words.sort() #list.sort( key=None, reverse=False)
#reverse -- 排序规则,reverse = True 降序, reverse = False 升序(默认)。
for word in words:
print(word,end=' ')
print()

 9 .多个组,每个测试组是一行,字符串通过空格隔开。

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_牛客网_09

while True:
try:
words=[x for x in input().strip().split()]
words.sort()
for word in words:
print(word,end=' ')
print()
except EOFError:
break

 10.多个组,每个测试组是一行,字符串通过空格隔开。输出:每个字符串间用','隔开,无结尾空格。

python3 牛客网:OJ在线编程常见输入输出练习(ACM模式)_python_10

while True:
try:
words=[x for x in input().strip().split(',')]
words.sort()
for word in words[:-1]:
print(word,end=',')
print(words[-1])
except EOFError:
break


举报

相关推荐

0 条评论