CCF 201312-2ISBN号码
思路:从第一个数字依次处理即可,先对取模后的答案进行处理转换为字符再判断
c++代码如下:
#include<string>
#include<iostream>
using namespace std;
int main(){
string s;
cin>>s;
int num = 0, count = 1;
for(int i = 0; i < s.size()-1; i++){
if(s[i] >= '0' && s[i] <= '9'){
num += (s[i] - '0') * count++;
}
}
num = num%11;
char ans;
if(num == 10) ans = 'X';
else ans = num + '0';
if(s[s.size()-1] == ans){
cout<<"Right"<<endl;
}
else{
string sub = s.substr(0, s.size()-1);
cout<<sub<<ans<<endl;
}
return 0;
}