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 yescrystal at 2006-08-15 04:57:39 on Problem 2190
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string ISBN;
	cin >> ISBN;
	int index = ISBN.find("?");
	int all=0, i, j, remainder=0, ans=0;
	for(j = 10,i=0; i<ISBN.size(); i++,j--) //j代表要乘的倍数
		if(i!=index)
		{
			if((int)ISBN[i]-'X'==0) all+=10*j; 
			else all += int(ISBN[i]-'0')*j;
		}
	remainder = all%11;
	if(remainder == 0)	                 	ans = 0;
	else if(remainder%(10-index)==0)		ans = remainder / (10-index);
	else                                    ans = -1;
	if(index == string::npos)       		ans = -1;
	if(index == 9 && remainder==10) 		cout << "X\n";
	else cout << ans << 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