1159. Sum
Description
Given several positive integers, calculate the sum of them.
Input
There are several test cases, one line for each case. For each line, the first number, N (N<=100000), is the number of positive numbers and then N positive numbers followed. The sum will not exceed 10100.
Output
Output each sum in a single line without leading zeros.
Sample Input
3 1 2 3
1 123
2 1111111111111111111111111111111111 1111111111111111111111111111111111
Sample Output
6
123
2222222222222222222222222222222222
Problem Source
ZSUACM Team Member
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main()
{
int t;
while(cin>>t)
{
int a[101]={0},max=0;
string str;
for(int i=1;i<=t;i++)
{
cin>>str;
if(str.length()>max) max=str.length();
for(int j=str.length()-1;j>=0;j--)
{
a[str.length()-1-j]+=(str[j]-'0');
}
for(int k=0;k<str.length();k++)
{
if(a[k]>=10)
{
a[k+1]++;
a[k]%=10;
}
}
}
if(a[max]>0) cout<<a[max];
for(int j=max-1;j>=0;j--)
cout<<a[j];
cout<<endl;
}
return 0;
}