如题:http://poj.org/problem?id=1503
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 31021 | Accepted: 12073 |
Description
``This supercomputer is great,'' remarked Chip. ``I only wish Timothy were here to see these results.'' (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky apartments on Third Street.)
Input
The final input line will contain a single zero on a line by itself.
Output
Sample Input
123456789012345678901234567890 123456789012345678901234567890 123456789012345678901234567890 0
Sample Output
370370367037037036703703703670
Source
思路: 简单的高精度加法。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define max(a,b)(a>b?a:b)
int res[200];
int main()
{
// freopen("C:\\1.txt","r",stdin);
int i,j=0;
char s1[300];
while(~scanf("%s",s1))
{
int len=strlen(s1);
if(len==1&&s1[0]=='0')
break;
j=0;
for(i=len-1;i>=0;i--)
{
res[j]+=s1[i]-'0';
res[j+1]+=res[j]/10;
res[j]%=10;
j++;
}
while(res[j]>9)
{
res[j+1]+=res[j]/10;
res[j]%=10;
j++;
}
}
int k=199;
while(!res[k])
k--;
for(i=k;i>=0;i--)
printf("%d",res[i]);
printf("\n");
}