Noah2013 @ 2024-06-01 20:03:53
#include<bits/stdc++.h>
using namespace std;
string ISBN;
int main(){
cin>>ISBN;//x-xxx-xxxxx-x-
int last=(ISBN[0]-'0')*1+(ISBN[2]-'0')*2+(ISBN[3]-'0')*3+(ISBN[4]-'0')*4+(ISBN[6]-'0')*5+(ISBN[7]-'0')*6+(ISBN[8]-'0')*7+(ISBN[9]-'0')*8+(ISBN[10]-'0')*9;
last=last%11;
char c;
if(ISBN[12]!='X'&&last!=10&&ISBN[12]-'0'==last) cout<<"Right"<<endl;
else if(ISBN[12]=='X'&&last==10) cout<<"Right"<<endl;
else{
cout<<"Wrong"<<endl;
for(int i=0;i<ISBN.length()-1;i++) cout<<ISBN[i];
if(last==10){
c='X';
cout<<c;
}
else cout<<last;
}
return 0;
}
by Malkin_Moonlight @ 2024-06-01 20:35:36
#include<bits/stdc++.h>
using namespace std;
char a[15];
int main(){
int sum=0,x=0;
cin>>a;
for(int i=0;i<11;i++){
if(a[i]>='0' && a[i]<='9'){
if(x==0){
sum+=1*(a[i]-48);
x++;
}else if(x==1){
sum+=2*(a[i]-48);
x++;
}else if(x==2){
sum+=3*(a[i]-48);
x++;
}else if(x==3){
sum+=4*(a[i]-48);
x++;
}else if(x==4){
sum+=5*(a[i]-48);
x++;
}else if(x==5){
sum+=6*(a[i]-48);
x++;
}else if(x==6){
sum+=7*(a[i]-48);
x++;
}else if(x==7){
sum+=8*(a[i]-48);
x++;
}else if(x==8){
sum+=9*(a[i]-48);
x++;
}
}
}
if(sum%11==(a[12]-48)){
cout<<"Right";
}else if(sum%11==10 && a[12]=='X'){
cout<<"Right";
}else{
if(sum%11==10){
a[12]='X';
}else{
a[12]=sum%11+48;
}
cout<<a;
}
return 0;
}