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

终于被AC了

Posted by 121mh at 2011-04-13 12:15:53
#include<iostream>
using namespace std;
int main(){
	int i=0,j=0;
	int num=0;
	char n[10];//用来接收输入的字符串
	int n_1[10];//用来存放ISBN码,
	cin>>n;
	for(i=0;i<10;i++){
		if(n[i]!='?'){
			if((i==9)&&n[i]=='X')// 判断最后一个字符是不是'X',
			{                    
				n_1[i]=10;       
				num+=(n_1[i]*(10-i));
			}
			else{
				n_1[i]=(int)n[i]-48;//如果这个字符不是'?','X',即是数字,那么把这个数字转化成对应的整数。
				num+=(n_1[i]*(10-i));
			}
		}
		else j=10-i;
	}
    if(j>1){
		for(i=0;i<10;i++){
			if((num+i*j)%11==0)//判断前面的累加和num与i*j的和是不是能被11整除,如果可以那么i就是'?'所代表的数字。
			{
				cout<<i;      
				return 0;     
			}
		}
	
	}
	else// 否则,问号出现在最后一位,那么'?'可以代表的值会是0~9,X。
	{
		for(i=0;i<=10;i++){
			if((num+i*j)%11==0)//判断前面的累加和num与i*j的和是不是能被11整除,如果可以那么i就是'?'所代表的数字。
			{
				if(i==10)        
					cout<<'X'<<endl;
				else
				 cout<<i;
				 return 0;
				
			}
		}
	}
    cout<<-1;
	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