L1-025 正整数A+B (15 分)

摘要
Title: L1-025 正整数A+B (15 分)
Tag: 模拟
Memory Limit: 64 MB
Time Limit: 1000 ms

Powered by:NEFU AB-IN

Link

L1-025 正整数A+B (15 分)

  • 题意

    题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000]。稍微有点麻烦的是,输入并不保证是两个正整数。

  • 思路

    熟练应用好字符串自带的函数,如upper,isdigit,isalpha...upper,isdigit,isalpha...

  • 代码

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    def judge(x):
    if x.isdigit() and 1 <= int(x) <= 1000:
    return 1
    return 0

    s = input().split()

    a, b = "?", "?"

    if len(s) == 2:
    if judge(s[0]): a = int(s[0])
    if judge(s[1]): b = int(s[1])
    else:
    if judge(s[0]): a = int(s[0])
    flag = 0
    if a == "?" or b == "?":
    flag = 1

    if flag:
    ans = "?"
    else:
    ans = a + b
    print(f"{a} + {b} = {ans}")
使用搜索:谷歌必应百度