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

不明WA...不过也不企望知道为什么了...姑且贴贴代码...

Posted by Airymok at 2009-03-01 19:04:58 on Problem 1503
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string s,sum;
	int C;
	int count,len0,len1;

	sum = "0";
	while (1)
	{
		cin >> s;
		if (s == "0") break;

		if (sum.length() <= s.length()) {
			string temp;
			temp = sum;sum = s;s = temp;
			sum.insert(0,"0");
		}
		int len = s.length();
		for (int j = 0;j < sum.length() - len;j++)
		s.insert(0,"0");
	//每次输入加数以后,都会在加数前面补一个‘0’,用于最高位进位。		
		C = 0;
		for (int j = s.length() - 1;j >= 0;j--)
		{
			sum[j] += s[j] - '0' + C;
			if (sum[j] >= '0' + 10) {
				sum[j] -= 10;
				C = 1;
			}
			else C = 0;
		}
	}

	if (sum != "0") {
		int index = sum.find_first_not_of("0");
		if (index != string::npos)
			sum = sum.substr(index);
		else sum = "0";
			cout << sum << endl;
	}
	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