I made some changes
查看原帖
I made some changes
1043309
rqliushuangyu楼主2024/7/21 18:58

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;
}
2024/7/21 18:58
加载中...