蒟蒻求助在线等QWQ

P1601 A+B Problem(高精)

@[EarthGiao](/space/show?uid=186489) 帮你改了一下。 ```cpp #include<iostream> #include<cstring> #include<string> #include<cstdio> using namespace std; int a[501],b[501],c[501]; char a1[502],b1[501]; int main() { memset(a,0,sizeof(a));//全部清零,不过不太重要因为数组定义在int main外面自定义值为0,清不清0无所谓保险起见清零 memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); scanf("%s",a1); scanf("%s",b1); int la1=strlen(a1); int lb1=strlen(b1);//长度 for(int i=0;i<la1;++i)// 将字符转换为数字,并且将原来的0-la1-1转为了,la1-1 { a[la1-i]=a1[i]-'0'; } for(int i=0;i<lb1;++i)//同上的,也是讲字符转化为数字,只需要减去字符0就好了 { b[lb1-i]=b1[i]-'0'; } int lc1=1,x=0;//x记录满十进一的进一 while(lc1<=la1||lc1<=lb1)//结束条件 { c[lc1]=a[lc1]+b[lc1]+x; x=c[lc1]/10; c[lc1]=c[lc1]%10; lc1++; } c[lc1]=x; if(c[lc1]==0)lc1--;//是零的话减减,不是的话输出 for(int i=lc1;i>=1;i--) { cout<<c[i];//这里输出 } cout<<endl; return 0; } ```
by Smile_Cindy @ 2019-04-01 09:58:52


@[Alpha](/space/show?uid=87058) 谢谢大佬
by EarthGiao @ 2019-04-01 10:01:02


@[Alpha](/space/show?uid=87058) 不过大佬为什么改成scanf就可以了而用get却爆零呢
by EarthGiao @ 2019-04-01 10:04:18


@[EarthGiao](/space/show?uid=186489) gets的话会出现一些奇奇怪怪的问题,不要乱用。
by Smile_Cindy @ 2019-04-01 10:06:01


@[Alpha](/space/show?uid=87058) 了解,谢谢
by EarthGiao @ 2019-04-01 10:07:09


|