题目简单,用string类就可以搞定
代码如下:
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
cin>>s;
int sum = 0,j = 1;
for(int i = 0; i < s.size() - 1; i++){
if(s[i] != '-'){
sum += (s[i] - '0')*j++;
}
}
int tmp = sum % 11;
if(tmp == 10){
if(s[s.size()-1] == 'X'){
cout<<"Right"<<endl;
}
else{
s[s.size()-1] = 'X';
cout<<s<<endl;
}
}
else if(tmp != 10){
if(s[s.size()-1] == tmp + '0'){
cout<<"Right"<<endl;
}
else{
s[s.size()-1] = tmp + '0';
cout<<s<<endl;
}
}
}