python程序的输入输出(acm的几个小程序)
2013-06-02 19:34
567 查看
1, A+B Problem : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1000
下面的代码只有一行,,可惜不是我想出来的!!!!:
2, A+B for Input-Output Practice (I) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1010
3, A+B for Input-Output Practice (II) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1011
4, A+B for Input-Output Practice (III) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1012
5, A+B for Input-Output Practice (IV) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1013
这段代码应该算是被我水过的,我是直接将这一行读取,然后所有的数相加,然后再减去 t (应该读入的数字的个数),并没有按照题目要求来,,呵呵,,先这样吧,
6, A+B for Input-Output Practice (V) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1014
7, A+B for Input-Output Practice (VI) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1015
8, A+B for Input-Output Practice (VII) : http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1016
被打败了,被'\r'打败了,,输出一个空行,,不解释
附 : python转义字符:
在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符。如下表:
原始字符串有时我们并不想让转义字符生效,我们只想显示字符串原来的意思,这就要用r和R来定义原始字符串。 如: print r'\t\r' 实际输出为“\t\r”。
#!/usr/bin/env python # coding=utf-8 a=[] for x in raw_input().split(): a.append(int(x)) print sum(a)
下面的代码只有一行,,可惜不是我想出来的!!!!:
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=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
这段代码应该算是被我水过的,我是直接将这一行读取,然后所有的数相加,然后再减去 t (应该读入的数字的个数),并没有按照题目要求来,,呵呵,,先这样吧,
#!/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 | 其它的字符以普通格式输出 |
相关文章推荐
- python程序的输入输出(acm的几个小程序)
- python学习—几个简单小程序
- 使用python写程序时遇到的几个小问题
- 树莓派用Python写几个简单程序
- [ACM训练] ACM中巧用文件的输入输出来改写acm程序的输入输出 + ACM中八大输入输出格式
- 几个适合python初学者的简单小程序,看完受益匪浅!
- 树莓派用Python写几个简单程序3_UART_BT-HM10
- Python3的ACM输入输出格式
- 树莓派用Python写几个简单程序4_UART
- [转]几个python 入门程序--例2( 如何将多个模块打包成一个模块)
- 树莓派用python写几个简单程序2_GPIO控制
- 树莓派用Python写几个简单程序5:用socket传图像
- 用python实现一个socket echo程序 && tcp socket的几个关闭状态
- 几个python小程序
- python几个简单的入门程序
- Python3的ACM输入输出格式
- 树莓派用Python写几个简单程序6_yeelink平台
- python编写借助linux中的xinetd守护进程实现我们的网络程序(select、重定向标准输入输出)
- 用python实现一个socket echo程序 && tcp socket的几个关闭状态
- python几个小程序