1, A+B Problem : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1000php
#!/usr/bin/env python # coding=utf-8 a=[] for x in raw_input().split(): a.append(int(x)) print sum(a)
下面的代碼只有一行,,惋惜不是我想出來的!!!!:python
print sum(int(x) for x in raw_input().split())
2, A+B for Input-Output Practice (I) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1010app
while True: a=[] line = raw_input() if line: for x in line.split(): a.append(int(x)) print sum(a) else: break
3, A+B for Input-Output Practice (II) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1011spa
#!/usr/bin/env python #coding:utf8 t = int(raw_input()) while t>0: a=[] for x in raw_input().split(): a.append(int(x)) print sum(a) t=t-1
4, A+B for Input-Output Practice (III) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1012code
#!/usr/bin/env python #coding:utf8 while True: line = raw_input() a=[] for x in line.split(): a.append(int(x)) if a[0]==0 and a[1]==0: break print sum(a)
5, A+B for Input-Output Practice (IV) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1013blog
這段代碼應該算是被我水過的,我是直接將這一行讀取,而後全部的數相加,而後再減去 t (應該讀入的數字的個數),並無按照題目要求來,,呵呵,,先這樣吧,utf-8
#!/usr/bin/env python #coding:utf8 while True: num=[] line = raw_input() for x in line.split(): num.append(int(x)) if num[0]==0: break a=num[0] print sum(num)-a
6, A+B for Input-Output Practice (V) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1014ci
#!/usr/bin/env python #coding:utf8 t = int(raw_input()) while t>0: if t==0: break line = raw_input() num=[] for x in line.split(): num.append(int(x)) print sum(num)-num[0] t = t-1
7, A+B for Input-Output Practice (VI) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1015字符串
#!/usr/bin/env python #coding:utf8 while True: line = raw_input() num=[] for x in line.split(): num.append(int(x)) print sum(num)-num[0]
8, A+B for Input-Output Practice (VII) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1016get
被戰勝了,被'\r'戰勝了,,輸出一個空行,,不解釋
#!/usr/bin/env python #coding:utf8 while True: a=[] line = raw_input() for x in line.split(): a.append(int(x)) print sum(a) print '\r' #輸出一個空行
附 : python轉義字符:
在須要在字符中使用特殊字符時,python用反斜槓(\)轉義字符。以下表:
轉義字符 | 描述 |
---|---|
\(在行尾時) | 續行符 |
\\ | 反斜槓符號 |
\' | 單引號 |
\" | 雙引號 |
\a | 響鈴 |
\b | 退格(Backspace) |
\e | 轉義 |
\000 | 空 |
\n | 換行 |
\v | 縱向製表符 |
\t | 橫向製表符 |
\r | 回車 |
\f | 換頁 |
\oyy | 八進制數yy表明的字符,例如:\o12表明換行 |
\xyy | 十進制數yy表明的字符,例如:\x0a表明換行 |
\other | 其它的字符以普通格式輸出 |
#!/usr/bin/env python #coding:utf8 t = int(raw_input()) while t>0: line = raw_input() num = [] for x in line.split(): num.append(int(x)) print sum(num)-num[0] t = t-1 if t!=0: print '\r'