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 <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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator