水题不解释~
AC代码:
#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
int main(){
string str;
cin>>str;
int ans = 0;
int cnt = 0; //cnt用来统计出现的数字个数
for(int i = 0;i <str.size() - 1;i++){
if(str[i] - '0' >= 0 && str[i] - '0' <= 9){
cnt++;
ans = ans + (str[i] - '0')*cnt;
}
}
ans = ans % 11;
int linshi; //最后的识别码
if(str[str.size() - 1] == 'X'){
linshi = 10;
}
else{
linshi = str[str.size() - 1] - '0';
}
if(ans == linshi){
printf("Right");
}
else{
for(int i = 0;i <str.size() - 1;i++){
printf("%c",str[i]);
}
if(ans == 10){
printf("X");
}
else{
printf("%d",ans);
}
}
}