| ||||||||||
| 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 | |||||||||
呵呵~ 。。。In Reply To:不好意思 自己发现一处严重错误 改后AC了 呵呵~ Posted by:yescrystal at 2006-08-15 05:08:17 #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=-1;
for(j = 10,i=0; i<ISBN.size(); i++,j--) //j代表要乘的倍数
{
if(i!=index)
{
if(ISBN[i]=='X' && i==9) all+=10;
else all += int(ISBN[i]-'0')*j;
}
}
remainder = (11-all%11)%11;
for(i=0;i<10; i++)
{
if((i*(10-index)-remainder)%11 == 0)
{ ans = i; break; }
}
if(index == 9 && remainder==10) cout << "X\n";
else cout << ans << endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator