02:Integer Inquiry

#include<iostream>
#include<string>
using namespace std;
int sum[201];
string s;
int main()
{
    while(cin>>s&&!(s.length()==1&&s[0]=='0'))
    {
        int x=s.length();
        int cnt=x-1;
        while(cnt>=0)
        {
            sum[200-x+1+cnt]+=s[cnt]-48;
            cnt--;
        }
    }
    for(int i=200;i>=0;i--)
    {
        if(sum[i]>=10)
        {
            sum[i-1]+=sum[i]/10;
            sum[i]%=10;
        }
    }
    int cnt=0;
    while(sum[cnt]==0)
    cnt++;
    for(int i=cnt;i<=200;i++)
    cout<<sum[i];
}

 

你可能感兴趣的:(02:Integer Inquiry)