20分求助!!!(玄关)

P1055 [NOIP2008 普及组] ISBN 号码

一个判断就好了 ```cpp #include<bits/stdc++.h> using namespace std; string s; int main(){ cin>>s; int sum=(s[0]-'0')*1+(s[2]-'0')*2+(s[3]-'0')*3+(s[4]-'0')*4+(s[6]-'0')*5+(s[7]-'0')*6+(s[8]-'0')*7+(s[9]-'0')*8+(s[10]-'0')*9; sum%=11; if (s[12]==(sum==10?'X':sum+'0')) cout<<"Right"; else { s[12]=(sum==10?'X':sum+'0'); cout<<s; } return 0; } ```
by _YTY_ @ 2023-09-06 19:13:18


@[joker__wang](/user/411060) 给你的代码改了一下 ``` #include<bits/stdc++.h> using namespace std; char a[100]; int t,l=1; int main() { cin>>a; for(int i=0;i<=strlen(a)-2;i++) { if(a[i]=='-') { continue; } else { t+=(a[i]-'0')*l; l++; } } if(t%11==a[strlen(a)-1]-'0') { cout<<"Right"; } else if(t%11>=10 && a[strlen(a)-1]=='X') { cout<<"Right"; } else { for(int i=0;i<=strlen(a)-2;i++) { cout<<a[i]; } if(t%11==10) { cout<<"X"; } else { cout<<t%11; } } } ``` 【汗】
by so_find_skind @ 2023-09-06 19:15:25


@[zhezhikongdanruxue](/user/756179) 大佬,-‘0’是什么意思
by joker__wang @ 2023-09-07 18:34:33


@[joker__wang](/user/411060) 就是把一个字符型的数字改成数字型的数字,因为实际上 $'1'=49$ 而非 $1$
by so_find_skind @ 2023-09-07 21:33:29


@[zhezhikongdanruxue](/user/756179) 谢谢
by joker__wang @ 2023-09-09 17:26:51


|