Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

错误是如何产生的呢?

Posted by BlueBlood at 2005-03-26 12:35:22 on Problem 1503
#include <iostream>
#include <cstdlib>
#include <string>

using namespace std;

int main()
{
    int n;
    int i;
    int VeryLongInt[101];
    int Sum[101];
    string s;
    
    for (i=0; i<101; i++)
        Sum[i] = VeryLongInt[i] = 0;
        
    while (cin >> n)
    {
        for (i=0; i<101; i++)
        Sum[i] = VeryLongInt[i] = 0;
        
        while (1)
        {
            cin >> s;
            int len = s.length();
            
            if (len == 1 && s[0] == '0')
                break;
            for (i= 0; i<len; i++)
                VeryLongInt[i] = s[len-i-1] - '0'; 
            int carry =0;
            for (i=0; i<101; i++)
            {
                Sum[i] += (carry + VeryLongInt[i]);
                if (Sum[i] >= 10)
                {
                    carry = 1;
                    Sum[i] %= 10;
                } 
                else
                    carry = 0;   
            }                   
        }    
        
        i = 100;
        while (i >=0 && Sum[i] == 0)
            i--;
        if (i < 0)
          cout << 0 << endl;
        else 
        {
            while (i>=0 )
              cout << Sum[i--];
            cout << endl;
        }    
        cout << endl;    
    }    
    system("PAUSE");
    return 0;
}    

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator