UVa-424-Integer Inquiry

AOAPC I: Beginning Algorithm Contests (Rujia Liu) :: Volume 1. Elementary Problem Solving :: Big Number


 

// 424 - Integer Inquiry
#include <iostream>
#include <cstring>
using namespace std;
int main(void)
{
    char s[200];    // at most 100 lines of text
    int i, k, n, carry, a[200], t[200];
    memset(a, 0, sizeof(a));
    while(cin>>s && s[0]!='0')
    {
        k = 0;
        carry = 0;
        memset(t, 0, sizeof(t));
 
        for(i=strlen(s)-1; i>=0; i--)
            t[k++] = s[i] - '0';
 
        for(i=0; i<200; i++)
        {
            carry += t[i] + a[i];
            a[i] = carry % 10;
            carry /= 10;
        }
    }
 
    n = 200;
    while(!a[--n]);
    for(i=n; i>=0; i--)
        cout << a[i];
    cout << endl;
    return 0;
}


 

posted @ 2014-08-09 17:26  颜威  阅读(118)  评论(0编辑  收藏  举报