poj 1503Integer Inquiry(高精度 水题)

              为啥同一代码G++和C++提交的相差这吗大呢…

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    int len, max=0, i, j;
    int sum[103]={0};
    int a[101];
    while( cin>>str && str!="0")
    {
        len=str.length();
        if( max<len )//记录位数最多的大数的位数
             max=len;
        j=0;
        for(i=len-1; i>=0; i--)//将输入的大数倒序存进数组a中
            a[j++]=str[i]-'0';
        for( i=0; i<len; i++)
        {
            sum[i]+=a[i];
            if( sum[i]>=10 )
            {
                sum[i+1]+=sum[i]/10;
                sum[i]-=10;
            }
        }
    }
    for(i=max+2; i>=0; i--)//多个大数和最多有max+2位
    {
        if( sum[i]!=0)//当第一个数不为0时开始输出
        {
            while( i>=0 )
            {
                cout<<sum[i];
                i--;
            }
            cout<<endl;
            break;
        }
    }
}



你可能感兴趣的:(c,String,Integer)