本文主要是介绍牛客网输入输出11道题——python3版本,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
- 1 介绍
- 2 训练
- 3 参考
1 介绍
本博客用来记录python3版本的常见输入输出。
2 训练
题目1:A+B(1)
python3代码如下,
import sys for line in sys.stdin:a, b = map(int, line.split())print(a+b)
题目2:A+B(2)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for i,line in enumerate(lines):if i != 0:a, b = map(int, line.split())print(a+b)
题目3:A+B(3)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for line in lines:a, b = map(int, line.split())if a != 0 and b != 0:print(a+b)
题目4:A+B(4)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for line in lines:nums = line.split()nums = [int(x) for x in nums]if nums[0] != 0:print(sum(nums[1:]))
题目5:A+B(5)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for i,line in enumerate(lines):if i != 0:line = line.split()line = [int(x) for x in line]print(sum(line[1:]))
题目6:A+B(6)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for line in lines:line = line.split()line = [int(x) for x in line]print(sum(line[1:]))
题目7:A+B(7)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for line in lines:line = line.split()line = [int(x) for x in line]print(sum(line))
题目8:字符串排序(1)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
words = lines[1].split()
words.sort()
res = " ".join(words)
print(res)
题目9:字符串排序(2)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for line in lines:words = line.split()words.sort()res = " ".join(words)print(res)
题目10:字符串排序(3)
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
for line in lines:words = line.split(',')words.sort()res = ",".join(words)print(res)
题目11:自测本地通过提交为0
python3代码如下,
import sys s = sys.stdin.read()
lines = s.splitlines()
a, b = map(int, lines[0].split())
print(a+b)
3 参考
OJ在线编程常见输入输出练习场
OJ在线编程常见输入输出练习
这篇关于牛客网输入输出11道题——python3版本的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!