(转)Python3的ACM输入输出格式

第一种多组输入模板格式:

while True:
    try:
        caption = list(map(int, input().split()))
        ans = 0
        for i in caption:
            ans += i
        print(ans)
    except EOFError:
        break

第一种模板适合那些没有告诉有多少组数据,只是让你不断地输入,典型的题型如A+B问题。

第二种有限输入模板格式:

T = int(input())
for case in range(T):
    caption = list(map(int, input().split()))
    ans = 0
    for i in caption:
        ans += i
    print(ans)

第二种模板格式适合题目要求首先输入一个整数,代表有几组输入,然后再输入每组数据的具体值。

第三种

 while True :

    try :

        a = input().strip().split()

    except EOFError:

        break

发布了82 篇原创文章 · 获赞 265 · 访问量 58万+

猜你喜欢

转载自blog.csdn.net/zhiyeegao/article/details/88203093