UVA 424

#include<iostream>
#include<cstring>
#include<string>
using namespace std;
const int max=1000;
struct bign
{
    int len;
    int  s[max];
};
void init_bign(bign &b)
{
    memset(b.s,0,sizeof(b.s));
    b.len=1;
}
void fuzi_bign(bign &b,char *num)
{
    b.len=strlen(num);
    for(int i=0;i<b.len;i++)
        b.s[i]=num[b.len-i-1]-'0';
}

bign jiafa_bign(bign &a,bign &b)
{
    bign c;
    c.len=0;
    for(int i=0,g=0;g||i<(a.len>=b.len?a.len:b.len);i++)
    {
        int x=g;
        if(i<a.len)x+=a.s[i];
        if(i<b.len)x+=b.s[i];
        c.s[c.len++]=x%10;
        g=x/10;
    }
    return c;
}

int main()
{    
    char aa[1000];
    bign bignum;
    bign temp;
    while(cin.getline(aa,1000))
    {
        if(strcmp(aa,"0")==0)break;
        fuzi_bign(temp,aa);
        bignum=jiafa_bign(temp,bignum);
    }
    for(int j=bignum.len-1;j>=0;j--)
        cout<<bignum.s[j];
    cout<<endl;
return 0;
}

 

posted @ 2012-04-29 09:28  open your eyes  阅读(305)  评论(0编辑  收藏  举报