文章

311

粉丝

4

获赞

385

访问

48.6k

头像
加减乘除 题解:注意使用//
P1267 北京大学机试题
发布于2026年2月5日 11:38
阅读数 136

while(1):
    try:
        s=list(map(str,input().split()))
        if(len(s)==2):
            a=int(s[0])
            count=1
            for i in range(1,a+1):
                count*=i
            print(count)
            continue
        a=int(s[0])
        b=int(s[2])
        if(s[1]=='+'):
            print(a+b)
        if(s[1]=='-'):
            print(a-b)
        if(s[1]=='*'):
            print(a*b)
        if(s[1]=='/'):
            if(b!=0):
                print(a//b)
            else:
                print("error")
        if (s[1] == '%'):
            if (b != 0):
                print(a%b)
            else:
                print("error")
    except:
        break
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发