HuasirF @ 2024-11-07 14:12:08
#include <stdio.h>
int main() {
char x[14];
scanf("%13s", x);
x[13] = '\0';
int n = 0;
//遍历x,如果是数字,就累加到count
int count = 0;
int value = 1;
//累加计算
for (int i = 0; i < 12; i++) {
if (x[i] >= '0' && x[i] <= '9') {
count += ((x[i] - '0') * value);
value++;
}
}
//count mod 11
int end = count % 11;
if (end == (x[12] - '0')) {
printf("Right\n");
}
else {
if (end == 10) {
x[12] = 'X';
// == 10
}
else {
x[12] = end + '0';
}
printf("%s\n", x);
}
return 0;
}
by L_zaa_L @ 2024-11-07 14:35:21
@HuasirF 最后一位是 X 的,你可能判断错了
by HuasirF @ 2024-11-07 14:54:30
@L_zaa_L 输入的最后一位是X吗?,我测试的都可以的。
by HuasirF @ 2024-11-07 14:56:27
@L_zaa_L 1-670-92162-X -> 1-670-92162-X 1-670-92162-0 -> 1-670-92162-X 0-670-82162-X -> 0-670-82162-4
by HuasirF @ 2024-11-07 14:58:14
@L_zaa_L
1-670-92162-X -> 1-670-92162-X
1-670-92162-0 -> 1-670-92162-X
0-670-82162-X -> 0-670-82162-4
by L_zaa_L @ 2024-11-07 16:37:26
@HuasirF 1-670-92162-X -> 1-670-92162-X这个应该输出Right