rqliushuangyu @ 2024-07-21 18:58:52
Wrong, wrong, wrong. High precision addition is correct on other platforms. This is incorrect!!!
#include<bits/stdc++.h>
using namespace std;
struct stadd{
int sz[300],len;
void init(){
memset(sz,0,sizeof(sz));
len=0;
}
void input(){
string s;
cin>>s;
len=s.size();
for(int i=0;i<len;i++){
sz[len-i-1]=s[i]-'0';
}
}
void output(){
bool x=true;
for(int i=len-1;i>=0;i--){
if(!x || sz[i]>0){
cout<<sz[i];
x=false;
}
}
}
}; void add(stadd a,stadd b,stadd *c){ c->init();
int m=max(a.len,b.len);
c->len=m;
int x=0;
for(int i=0;i<m;i++){
c->sz[i]+=a.sz[i]+b.sz[i];
x=c->sz[i]/10;
c->sz[i]%=10;
c->sz[i+1]=x;
}
if(x>0){
c->len++;
}
} stadd operator +(stadd a,stadd b){
stadd c;
c.init();
add(a,b,&c);
return c;
} int main(){
stadd a,b,c;
a.init();
b.init();
c.init();
a.input();
b.input();
c=a+b;
c.output();
return 0;
}
by ssine233 @ 2024-07-21 19:02:36
我寻思这也不是国际站啊
by OIerWu_829 @ 2024-07-21 19:03:59
@ssine233 不是正在改造国际版吗()
by ssine233 @ 2024-07-21 19:06:19
@wzj0829 你说的好像没有问题
by zhouxianzhuo @ 2024-07-21 19:16:48
这用户名咋那么像中国人
by rqliushuangyu @ 2024-07-21 19:24:09
额,各位,我……我是中国的!!练习一下英语,我这是改后的,用对啦(我是个学生)