1.輸入描述
輸入包括兩個正整數a,b(1 <= a, b <= 10^9),輸入數據包括多組。
輸入 1 5
輸出 6
while True: try: a,b = map(int, input().split()) print(a+b) except: break
while True: try: num=input().split() num=list(map(int,num)) print(num[0]+num[1]) except: break
2.輸入描述
輸入第一行包括一個數據組數t(1 <= t <= 100)
接下來每行包括兩個正整數a,b(1 <= a, b <= 10^9)
輸入
2 1 5 10 20
輸出
6 30
n = int(input()) for i in range(n): a = input().split() print(int(a[0])+int(a[1]))
import sys n = int(input()) for i in range(n): a,b = map(int,input().split()) print(a + b)
3.輸入描述
輸入包括兩個正整數a,b(1 <= a, b <= 10^9),輸入數據有多組, 如果輸入為0 0則結束輸入
輸入:
1 5 10 20 0 0
輸出
6 30
while True: try: a,b = map(int, input().split()) if (a,b) == (0,0): break else: print(a+b) except: break
import sys for line in sys.stdin: line=line.split() temp=list(map(int,line)) if temp[0]==0 and temp[1]==0: break print(temp[0]+temp[1])
while True: try: temp=input().split() temp=list(map(int,temp)) if temp[0]==0 and temp[1]==0: break print(temp[0]+temp[1]) except: break
4.輸入描述
輸入的第一行包括一個正整數t(1 <= t <= 100), 表示數據組數。
接下來t行, 每行一組數據。
每行的第一個整數為整數的個數n(1 <= n <= 100)。
接下來n個正整數, 即需要求和的每個正整數。
輸入:
2 4 1 2 3 4 5 1 2 3 4 5
輸出:
10 15
t = int(input()) for i in range(t): a = list(map(int, input().split())) if a[0]!=0: print(sum(a)-a[0]) else: break
import sys for ind, line in enumerate(sys.stdin): if ind == 0: t = int(line) else: line = line.split() line = list(map(int,line)) s = sum(line[1:]) print(s)
5.輸入描述
輸入有兩行,第一行n
第二行是n個空格隔開的字符串
輸入:
5 c d a bb e
輸出:
a bb c d e
n = int(input()) strlist = list(map(str, input().split())) strlist.sort() print(" ".join(strlist))
while True: try: a = int(input()) b = list(map(str, input().split(" "))) b.sort() print(" ".join(b)) except: break
6.題目描述
對於每組測試用例,輸出一行排序過的字符串,每個字符串通過空格隔開
輸入:
a c bb f dddd nowcoder
輸出:
a bb c dddd f nowcoder
import sys for line in sys.stdin: line = line.split() temp = list(map(str,line)) temp.sort() print(" ".join(temp))
while True: try: line = input().split() line = list(map(str, line)) line = sorted(line) print(' '.join(line)) except: break
7輸入描述
多個測試用例,每個測試用例一行。
每行通過,隔開,有n個字符,n<100
輸入:
a,c,bb f,dddd nowcoder
輸出:
a,bb,c dddd,f nowcoder
import sys for line in sys.stdin: a=line.split() a=a[0].split(',') a.sort() c=','.join(a) print(c)
while True: try: line = input().split(',') line = sorted(line) print(','.join(line)) except: break