| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 33767 | Accepted: 13151 |
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 <stdio.h>
#include <string.h>
#include <stdlib.h>
main()
{
char str[150][150] = { 0 };
int num[150][150] = { 0 };
char new[150*150] = { 0 };
int i = 0, j = 0, k = 0, len = 0, lenmax = 0, len_new = 0, re = 0, sum = 0;
do
{
scanf("%s", str[i++]);
} while (strcmp(str[i - 1],"0") != 0);
for (j = 0;j<i-1;j++)
{
len = strlen(str[j]);
if (len>lenmax) lenmax = len;
for (k = 0;k<len;k++)
num[j][k] = str[j][len - k - 1] - '0';
}
for (j = 0;j<lenmax;j++)
{
for (k = 0;k<i;k++)
sum += num[k][j];
sum += re;
new[j] = sum % 10+'0';
re = sum / 10;
sum = 0;
}
while (re != 0)
{
new[j] = re % 10+'0';
j++;
re = re / 10;
}
len_new = strlen(new);
for (i= len_new-1;i>=0;i--)
printf("%c", new[i]);
printf("\n");
return 0;
}
More:
#include<stdio.h>
#include<string.h>
int a[110];
char str[110];
void init(char s[], int a[])
{
int i, j, b[110];
int len = strlen(s);
int k = 0;
for (i = 0;i<len;i++)
b[len - i - 1] = s[i] - '0';
for (i = 0;i<len;i++)
{
a[i] = a[i] + b[i];
if (a[i] >= 10)
{
a[i] = a[i] - 10;
a[i + 1]++;
}
}
}
int main()
{
int t, i, j;
memset(a, 0, sizeof(a));
while (scanf("%s", &str) && strcmp(str, "0") != 0)
{
init(str, a);
}
for (i = 110;i>0;i--)
if (a[i])
break;
for (j = i;j >= 0;j--)
printf("%d", a[j]);
printf("\n");
return 0;
}
1万+



被折叠的 条评论
为什么被折叠?



