telankesi @ 2022-11-06 15:49:58
#include <stdio.h>
int main() {
char a[10];
scanf("%c-%c%c%c-%c%c%c%c%c-%c", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9]);
int sum=0;
for (int i = 0; i < 9; i++) {
sum += (i + 1) * (a[i]-'0');
}
int x, y;
sum %= 11;
if (sum == 10) {
if (a[9] == 'X') printf("Right");
}
else if (sum == a[9]-'0')
printf("Right");
else {
if (sum == 10) a[9] = 'X';
else a[9] = sum+'0';
printf("%c-%c%c%c-%c%c%c%c%c-%c", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
}
return 0;
}
by sunnygreen @ 2022-11-06 16:02:53
@kakaluo_te 在
if (sum == 10) {
if (a[9] == 'X')
printf("Right");
else
{
a[9] = 'X';
printf("%c-%c%c%c-%c%c%c%c%c-%c", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
}
}
by telankesi @ 2022-11-06 16:18:52
@SCP_74751 我在下边写改正代码了啊
by sunnygreen @ 2022-11-06 21:18:32
不,这是在第
by sunnygreen @ 2022-11-06 21:19:31
改正代码:
#include <stdio.h>
char a[10];
int main() {
scanf("%c-%c%c%c-%c%c%c%c%c-%c", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &a[8], &a[9]);
int sum = 0;
for (int i = 0; i < 9; i++)
sum += (i + 1) * (a[i] - '0');
int x, y;
sum %= 11;
if (sum == 10) {
if (a[9] == 'X')
printf("Right");
/* 加入部分
else
{
a[9] = 'X';
printf("%c-%c%c%c-%c%c%c%c%c-%c", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
}
*/
}
else if (sum == a[9]-'0')
printf("Right");
else {
if (sum == 10) a[9] = 'X';
else a[9] = sum+'0';
printf("%c-%c%c%c-%c%c%c%c%c-%c", a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9]);
}
return 0;
}
by sunnygreen @ 2022-11-06 21:20:16
@kakaluo_te 加上 /* ... */
部分
by telankesi @ 2022-11-06 21:58:53
谢啦