Dev-C++运行结果:
11111111111111111111111111 9999999999999999999999999999999999 11111111111111111111111111 11111111111111111111111111
-49-49-49-49-48-48-48-4899999999999999999999999999 9999999999999999999999999999999999
-5-4-4-4-4-3-3-2-711111111111111111111111110
--------------------------------
Process exited after 2.627 seconds with return value 0
请按任意键继续. . .
代码:
#include"iostream"
#include"stdio.h"
#include"string"
#include"string.h"
using namespace std;
struct num{
int shuwei[500]={0},len;
string a;
num operator+(const num x)const{
num s;
s.len=len>x.len?len:x.len;
for(int i=0;i<s.len;i++)
s.shuwei[i]=shuwei[i]+x.shuwei[i];
for(int i=0;i<s.len;i++){
s.shuwei[i+1]+=s.shuwei[i]/10;
s.shuwei[i]%=10;
}
while(s.shuwei[s.len]){
s.shuwei[s.len+1]=s.shuwei[s.len]/10;
s.shuwei[s.len++]%=10;
}
return s;
}
}A,B,ans;
int main(void){
//freopen("P1601.in","r",stdin);//养成良好习惯
//freopen("P1601.out","w",stdout);//洛谷上提交不能加freopen,我只好注掉
ios::sync_with_stdio(false);
cin>>A.a>>B.a;
A.len=A.a.size();
B.len=B.a.size();
for(int i=0;i<A.len;i++)
A.shuwei[i]=A.a[A.len-i-1]-'0';
for(int i=0;i<B.len;i++)
B.shuwei[i]=B.a[A.len-i-1]-'0';
ans=A+B;
for(int i=A.len-1;i>=0;i--)//临时加的
cout<<A.shuwei[i];//临时加的
cout<<endl<<A.a<<endl;//临时加的
for(int i=B.len-1;i>=0;i--)//临时加的
cout<<B.shuwei[i];//临时加的
cout<<endl<<B.a<<endl;//临时加的
for(int i=ans.len-1;i>=0;i--)
cout<<ans.shuwei[i];
return 0;
}
(上面的输出结果是加了临时输出后的结果)