| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
测试数据都通过了。各位大哥帮一下忙啊,小妹感恩不尽!#include<iostream>
using namespace std;
int main()
{
int t;
char a[1000],b[1000],c[1000];
cin>>t;
while(t--)
{
cin>>a>>b;
int lena,lenb;
lena=strlen(a);
lenb=strlen(b);
int i;
if(lena<lenb)
{
for(i=lena;i<lenb;i++)
a[i]='0';
a[i]='\0';
}
else
{
for(i=lenb;i<lena;i++)
b[i]='0';
b[i]='\0';
}
int s=0,tmp;
for(i=0;a[i];i++)
{
tmp=a[i];
a[i]=(tmp-'0'+b[i]-'0'+s)%10+'0';
s=(tmp-'0'+b[i]-'0'+s)/10;
}
a[i++]=s+'0';
a[i]='\0';
for(i=lena;;i--)
if(a[i]!='0')break;
a[i+1]='\0';
for(i=0;;i++)
if(a[i]!='0')break;
cout<<a+i<<endl;
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator