python程序的標準輸入輸出

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用反斜槓(\)轉義字符。以下表:

原始字符串有時咱們並不想讓轉義字符生效,咱們只想顯示字符串原來的意思,這就要用r和R來定義原始字符串。      如:         print  r'\t\r'          實際輸出爲「\t\r」。

 

轉義字符 描述
\(在行尾時) 續行符
\\ 反斜槓符號
\' 單引號
\" 雙引號
\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'
複製代碼
相關文章
相關標籤/搜索