为什么样例数据没问题,他就是会“WA”掉?

P1601 A+B Problem(高精)

~~**希望更丰富的展现?使用Markdown**~~
by opened @ 2018-12-05 21:10:28


希望更丰富的展现?使用Markdown
by 33028120040712wcl @ 2018-12-05 21:10:59


@[opened](/space/show?uid=90615) 表示第一次发帖,容我学习一下怎么发出完整代码
by 打酱油路过 @ 2018-12-05 21:13:12


常数极大重载运算符(~~谨慎食用~~) ``` #include<iostream> #include<cstdio> using namespace std; const int maxn=5000; struct SuperNum{ int flag; int s[maxn]; SuperNum(){ flag=0; for(int i=1;i<maxn;i++) s[i]=0; s[0]=1; } SuperNum(string x){ flag=0; s[0]=x.length(); for(int i=1;i<=s[0];i++) s[i]=x[s[0]-i]-'0'; for (int i=s[0]+1;i<maxn;i++) s[i]=0; } }; SuperNum operator + (SuperNum a, SuperNum b){ SuperNum c; for(int i=0;i<maxn;i++) c.s[i]=0; c.s[0]=max(a.s[0],b.s[0]); int s,jw=0; for(int i=1;i<=c.s[0];i++){ s=a.s[i]+b.s[i]+jw; jw=s/10; c.s[i]=s%10; } if(jw){ c.s[0]+=1; c.s[c.s[0]]=jw; } return c; } bool operator < (SuperNum a, SuperNum b){ if(a.s[0]<b.s[0]) return 1; if(a.s[0]>b.s[0]) return 0; for(int i=a.s[0];i>=1;i--) if(a.s[i]>b.s[i]) return 0; else if(a.s[i]<b.s[i]) return 1; return 0; } void print(SuperNum c){ if(c.flag==1) cout<<"-"; for(int i=c.s[0];i>=1;i--) cout<<c.s[i]; } int main(){ string a,b; cin>>a>>b; SuperNum x(a),y(b); SuperNum a1=x+y; print(a1); cout<<endl; return 0; } ```
by opened @ 2018-12-05 21:14:22


@[打酱油路过](/space/show?uid=141842) 代码前后换行加```即可
by opened @ 2018-12-05 21:16:22


··· #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { char s1[500000],s2[500000]; int a[505],b[505],c[505],la,lb,lc,x,i; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); gets(s1); gets(s2); la=strlen(s1); lb=strlen(s2); for(i=0;i<la;i++) a[la-i]=s1[i]-'0'; for(i=0;i<lb;i++) b[lb-i]=s2[i]-'0'; lc=1; x=0; while(lc<=la||lc<=lb) { c[lc]=a[lc]+b[lc]+x; x=c[lc]/10; c[lc]%=10; lc++; } c[lc]=x; while(c[lc]==0&&lc>1)lc--; for(i=lc;i>=1;i--) cout<<c[i]; return 0; } ···
by 打酱油路过 @ 2018-12-05 21:18:32


``` #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { char s1[500000],s2[500000]; int a[505],b[505],c[505],la,lb,lc,x,i; memset(a,0,sizeof(a)); memset(b,0,sizeof(b)); memset(c,0,sizeof(c)); gets(s1); gets(s2); la=strlen(s1); lb=strlen(s2); for(i=0;i<la;i++) a[la-i]=s1[i]-'0'; for(i=0;i<lb;i++) b[lb-i]=s2[i]-'0'; lc=1; x=0; while(lc<=la||lc<=lb) { c[lc]=a[lc]+b[lc]+x; x=c[lc]/10; c[lc]%=10; lc++; } c[lc]=x; while(c[lc]==0&&lc>1)lc--; for(i=lc;i>=1;i--) cout<<c[i]; return 0; } ```
by 打酱油路过 @ 2018-12-05 21:19:31


@[opened](/space/show?uid=90615) 谢谢大佬
by 打酱油路过 @ 2018-12-05 21:20:06


建议将存数字的数组初始化为全0 [安利一下自己博客的高精板子](https://www.luogu.org/blog/WAFUN/gao-jing-mu-ban)
by _Qer @ 2018-12-05 21:26:54


|