Lucas530 @ 2023-10-06 12:16:19
#include <bits/stdc++.h>
using namespace std;
string s;
int sum = 0;
int cnt = 0;
int main () {
getline(cin, s);
for(int i = 0; i < 13; i++){
if(i == 1 || i == 5 || i == 11 || i == 12)
continue;
sum++;
cnt += (int)(s[i] - 48) * sum;
}
cnt %= 11;
if(cnt == 10){
cnt = (char)cnt;
cnt = 'X';
}else
cnt = (char)cnt;
if(cnt == ((int)s[12] - 48)){
cout << "Right";
return 0;
}
s[12] = (char)(cnt + 48);
cout << s;
return 0;
}
by wzt2012 @ 2023-10-06 12:52:20
@Lucas530 给个思路吧,你看看注释。
#include<bits/stdc++.h>
using namespace std;
string a;
char mod[12] = "0123456789X"; //把余数全部存下来就不用多判断了
int t = 0, j = 1;
int main(){
std::cin >> a;
for(int i = 0; i < 12; i ++){
if(a[i] == '-') continue;
t += (a[i] - 48) * j ++; //对前9位数字进行计算
}
if(mod[t % 11] == a[12]) cout << "Right"; //判断余数是否等于识别码
else{
a[12] = mod[t % 11];
std::cout << a << endl;
} //修正并输出
return 0;
}
by ArisakaMashiro @ 2023-10-06 12:54:37
#include <bits/stdc++.h>
using namespace std;
string s;
int sum = 0;
int cnt = 0;
char com;
int main () {
getline(cin, s);
for(int i = 0; i < 13; i++){
if(i == 1 || i == 5 || i == 11 || i == 12)
continue;
sum++;
cnt += (int)(s[i] - 48) * sum;
}
cnt %= 11;
if(cnt == 10){
com = 'X';
}else
com = (char)cnt + 48;
if(com == s[12]){
cout << "Right";
return 0;
}
s[12] = com;
cout << s;
return 0;
}
@Lucas530