| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
错误是如何产生的呢?#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator