问题 A: 又一版 A+B

花了很长时间,
1.首先题目中非负数可以是零啊,这个完全没有考虑。用do while循环可以完成对0的讨论。
2.其次就是及时换行,题目说明了每个输入用例占一行。
3.最重要的,hint也提示了要注意范围。int a 加 int b. long long c=a+b;是错的。必须a,b也为long long
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    int a = 2147483647;
    int a1= 2147483648;
    int b = 2147483647;
    long long c = 2147483648;
    long long d = a+b; //a = 0 真值的原码111111...(31个) (31个)111111111...0 原码相加 补码为10...00010,即-2
    long long e=2*c;
    cout<<a<<endl;
    cout<<a1<<endl;
    cout<<c<<endl;
    cout<<d<<endl;
  



#include<cstdio>
#include<iostream>
using namespace std;
int main(){
    long a,b;

    int m;
    int aa[1000];
    while(scanf("%d",&m)!=EOF&&m!=0){
        int num=0;
        scanf("%lld%lld",&a,&b);
        long long c = a+b;

    do
        {
        aa[num++]=c%m;
        c/=m;
        }while(c!=0);

        for(int i=num-1;i>=0;i--){
            printf("%d",aa[i]);

        }
         printf("\n");

    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值