ZOJ1292

#include  < iostream >
#include 
< string >
#include 
< cstring >
using   namespace  std;

const   int  MAX_SIZE  =   105 ;

int  Result[MAX_SIZE];
int  MaxLen;
string  str;

void  Init()
{
    
//memset(Result,sizeof(Result),0);
    for(int i = 0; i < MAX_SIZE; i++)
        Result[i] 
= 0;
}


void  Add()
{
    
int i,j;
    
if(MaxLen < str.length())
        MaxLen 
= str.length();
    
for(i = 0, j = str.length() - 1; j >= 0; i++,j--)
        Result[i] 
+= str[j]-'0';
}


int  main()
{
    
int n,jw,i,tmp;
    
while(cin>>n)
    
{
        
while(n--)
        
{
            Init();
            MaxLen 
= 0;
            
while(cin>>str && str != "0")
                Add();
            
for(i = 0, jw = 0;i < MaxLen; i++)
            
{
                tmp 
= Result[i] + jw;
                
if(tmp > 9)
                
{
                    jw 
= tmp / 10;
                    Result[i] 
= tmp % 10;
                }

                
else
                
{
                    Result[i] 
= tmp;
                    jw 
= 0;
                }

            }

            
if(jw)cout<<jw;
            
for(i = MaxLen - 1; i >= 0; i--)
                cout
<<Result[i];
            cout
<<endl;
            
if(n)cout<<endl;//There is a blank line between output blocks
        }

    }

    
return 0;
}

你可能感兴趣的:(ZOJ)