| ||||||||||
| 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 | |||||||||
好久没1A了 贴代码#include<stdio.h>
#include<string.h>
#define MAX 1001
void Clear(int a[])
{
int i;
for(i=0;i<MAX;++i)
a[i]=0;
}
void Add(int temp1[],int temp2[],int temp3[],int res[])
{
int i;
for(i=0;i<MAX;++i)
{
res[i]=res[i]+temp1[i]+temp2[i]+temp3[i];
if(res[i]>=20)
{
res[i]-=20;
res[i+1]+=2;
}
else if(res[i]>=10)
{
res[i]-=10;
res[i+1]+=1;
}
}
}
void Copy(int a[],int b[])
{
int i;
for(i=0;i<MAX;++i)
{
a[i]=b[i];
}
}
int main()
{
int a0,a1,a2;
while(scanf("%d%d%d",&a0,&a1,&a2)!=EOF)
{
if(a0==0 && a1==0 && a2==0)
{
printf("0\n");
continue;
}
int temp1[MAX],temp2[MAX],temp3[MAX],res[MAX];
memset(temp1,0,sizeof(temp1));
memset(temp2,0,sizeof(temp2));
memset(temp3,0,sizeof(temp3));
memset(res,0,sizeof(res));
int i,j;
j=0;
while(a0!=0)
{
temp1[j++]=a0%10;
a0/=10;
}
j=0;
while(a1!=0)
{
temp2[j++]=a1%10;
a1/=10;
}
j=0;
while(a2!=0)
{
temp3[j++]=a2%10;
a2/=10;
}
for(i=1;i<98;++i)
{
Clear(res);
Add(temp1,temp2,temp3,res);
Clear(temp1);
Copy(temp1,temp2);
Clear(temp2);
Copy(temp2,temp3);
Clear(temp3);
Copy(temp3,res);
}
for(i=MAX-1;res[i]==0;--i);
for(;i>=0;--i)
printf("%d",res[i]);
printf("\n");
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator