python程序的输入输出(acm的几个小程序)

1,  A+B Problem : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1000

#!/usr/bin/env python 
# coding=utf-8  
  
a=[]  
  
for x in raw_input().split():  
    a.append(int(x))  
  
print sum(a)  

 

2, A+B for Input-Output Practice (I) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1010

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=1011

#!/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=1012

#!/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=1013

#!/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=1014

#!/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=1016

被打败了,被'\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'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值