xhhwdn @ 2024-08-30 10:40:26
#include <bits/stdc++.h>
using namespace std;
int main() {
char inp[13] = {};
for (int i = 0; i < 13; i++) {
cin >> inp[i];
}
int num[9] = {};
num[0] = inp[0];
num[1] = inp[2];
num[2] = inp[3];
num[3] = inp[4];
num[4] = inp[6];
num[5] = inp[7];
num[6] = inp[8];
num[7] = inp[9];
num[8] = inp[10];
num[9]=inp[11];
char lastnum = inp[12];
int adder=0;
for (int i = 0; i < 8; i++) {
adder += num[i] * i + 1;
}
int check=0;
char x = 'X';
check = adder % 11;
char output=0;
if (check == 10) {
if (lastnum == 'X') {
cout << "Right";
} else {
output = num[0] + '-' + num[1] + num[2] + num[3] + '-' + num[4] + num[5] + num[6] + num[7] + num[8] + '-' + 'X';
cout << output;
}
} else {
if (lastnum == check) {
cout << "Right";
} else {
output = num[0] + '-' + num[1] + num[2] + num[3] + '-' + num[4] + num[5] + num[6] + num[7] + num[8] + '-' + check;
cout << output;
}
}
}
by Yxy7952 @ 2024-08-30 11:05:00
@xhhwdn
楼主,细节错误太多了,至少有20处,建议自己重写回顾一下,这是我调地你的代码,已AC,求关
#include <bits/stdc++.h>
using namespace std;
char inp[20];
int num[10];
int main() {
cin>>inp;
num[0] = inp[0]-'0';
num[1] = inp[2]-'0';
num[2] = inp[3]-'0';
num[3] = inp[4]-'0';
num[4] = inp[6]-'0';
num[5] = inp[7]-'0';
num[6] = inp[8]-'0';
num[7] = inp[9]-'0';
num[8] = inp[10]-'0';
char lastnum = inp[12];
int lastnum2 = inp[12]-'0';
int check=0;
for (int i = 0; i < 9; i++) {
check += num[i] * (i + 1) ;
}
check %= 11;
if (check == 10) {
if (lastnum == 'X') {
cout << "Right";
} else {
inp[12]='X';
cout<<inp;
}
} else {
if (lastnum2 == check) {
cout << "Right";
} else {
inp[12]=check+'0';
cout<<inp;
}
}
return 0;
}