题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
https://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
#include <cstdio> #include <iostream> #include <ostream> #include <string> using namespace std; int main() { int a, b, c; char d; while (scanf("%d-%d-%d-%c",&a,&b,&c,&d)==4) { // 注意 while 处理多个 case string e; e = to_string(a)+to_string(b)+to_string(c); int f=0; for(int i = 0;i<9;i++) { f += (e[i]-'0')*(i+1); } if(f%11==10 && d=='X') { cout<<"Right"<<endl; } else if(f%11==(d-'0')) { cout<<"Right"<<endl; } else if(f%11==10 && d!='X') { char g='X'; printf("%d-%d-%d-%c",a,b,c,g); } else { printf("%d-%d-%d-%d",a,b,c,f%11); } } } // 64 位输出请用 printf("%lld")
注意:如果使用string e=“1234”,e[0]=1应该是e[0]='1',想得到e[0]=1,应该是e[0]-'0'。另外可以多看看逻辑