Integer Inquiry

Integer Inquiry

Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Submit Status

Description

One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers. 
``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 input will consist of at most 100 lines of text, each of which contains a single VeryLongInteger. Each VeryLongInteger will be 100 or fewer characters in length, and will only contain digits (no VeryLongInteger will be negative).

The final input line will contain a single zero on a line by itself.

Output

Your program should output the sum of the VeryLongIntegers given in the input.

Sample Input

123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0

Sample Output

370370367037037036703703703670
 #include<stdio.h>
#include<string.h> char a[][] ;
char sum[] ; void add (char temp[] ) { int rem = ;
int k ;
int i ;
for (i = ; temp[i] != '\0' ; i++ ) {
if ( ( k = temp[i] - '' + sum[i] - '' + rem ) >= ) {
rem = ;
sum[i] = '' + k - ;
}
else {
rem = ;
sum[i] = '' + k ;
}
}
if ( rem == )
sum[i] = '' ;
for ( k = strlen (sum) - ; sum[k] == && k >= ; k-- ) ;
if ( k == -)
sum[k + ] = '\0' ;
else
sum[k + ] = '\0' ; } int main () {
// freopen ("a.txt" ,"r" , stdin ) ;
int n ;
int ls , li ;
int j ;
while ( gets(a[]) != NULL ) {
n = ;
while ( strcmp(a[n - ] , "") != ) {
gets (a[n++]) ;
}
strcpy (sum , a[] ) ;
strrev (sum) ; for (int i = ; i < n; i++ ) {
li = strlen (a[i]) ;
ls = strlen (sum) ;
strrev (a[i]) ;
if ( li > ls ) {
for (j = ls ; j < li ; j++ ) {
sum[j] = '' ;
}
sum[j] = '\0' ;
}
else {
for (j = li ; j < ls ; j++ ) {
a[i][j] = '' ;
}
a[i][j] = '\0' ;
}
add ( a[i] ) ;
}
strrev (sum) ;
puts (sum) ;
}
return ;
}

试试 1 + 9 或 直接输入 0

上一篇:使用Yeoman搭建 AngularJS 应用 (6) —— 让我们搭建一个网页应用


下一篇:微信公众号开发系列-开发环境要求和准备工作