牛客OJ在线编程常见输入输出练习(python版)

原文链接:https://blog.csdn.net/qq_41023125/article/details/105748780

先放上地址:https://ac.nowcoder.com/acm/contest/320#question

1、A+B(1)

在这里插入图片描述

while True:
    try:
        a, b = map(int, input().strip().split())
        print(a + b)
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

2、A+B(2)

在这里插入图片描述

while True:
    try:
        l = list(map(int, input().strip().split()))
        if len(l) == 1:
            pass
        else:
            print(sum(l))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

3、A+B(3)

在这里插入图片描述

while True:
    try:
        l = list(map(int,input().strip().split()))
        if l == [0,0]:
            break
        else:
            print(sum(l))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

4、A+B(4)

在这里插入图片描述

while True:
    try:
        l = list(map(int, input().strip().split()))
        if l[0] == 0:
            break
        else:
            print(sum(l[1:]))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

5、A+B(5)

在这里插入图片描述

while True:
    try:
        l = list(map(int,input().strip().split()))
        if len(l) == 1:
            pass
        else:
            print(sum(l[1:]))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

6、A+B(6)

在这里插入图片描述

while True:
    try:
        l = list(map(int, input().strip().split()))
        print(sum(l[1:]))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

7、A+B(7)

在这里插入图片描述

while True:
    try:
        l = list(map(int, input().strip().split()))
        print(sum(l))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

8、字符串排序(1)

在这里插入图片描述

while True:
    try:
        n=int(input())
        mystr=list(map(str,input().strip().split()))
        mystr.sort()
        print(' '.join(mystr))
    except EOFError:
        break

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

9、字符串排序(2)

在这里插入图片描述

from fileinput import input
for line in input():
    a = line.split()
    a = sorted(a)
    s = ''
    for i in range(len(a)-1):
        s+=a[i]+' '
    s += a[-1]
    print(s.lstrip())

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

10、字符串排序(3)

在这里插入图片描述

from fileinput import input
for line in input():
    a = sorted(line.strip().split(','))
    s = ''
    for i in range(len(a)-1):
        s+=a[i]+','
    s += a[-1]
    print(s)

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

参考:

                                </div><div><div></div></div>
            <link href="https://csdnimg.cn/release/phoenix/mdeditor/markdown_views-ff98e99283.css" rel="stylesheet">
                            </div>
  • 3
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值