HJRBill @ 2022-09-09 17:33:58
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
char arr[14];
scanf("%s", arr);
int one = (arr[0] - '0') * 1;
int two = (arr[2] - '0') * 2;
int three = (arr[3] - '0') * 3;
int four = (arr[4] - '0') * 4;
int five = (arr[6] - '0') * 5;
int six = (arr[7] - '0') * 6;
int seven = (arr[8] - '0') * 7;
int eight = (arr[9] - '0') * 8;
int nine = (arr[10] - '0') * 9;
int ten = arr[12] - '0';
int number = (one + two + three + four + five + six + seven + eight + nine) % 11;
if (ten == number)
{
printf("Right");
}
else if (number == 10 && ten != number)
{
arr[12] = 'X';
printf("%s", arr);
}
else
{
arr[12] = number + '0';
printf("%s", arr);
}
return 0;
}
by VectorLi @ 2022-09-09 17:53:01
@HJRBill 您没有考虑 arr[12]
为
by _Hu_Tao @ 2022-09-09 17:53:28
细节问题
因为number有可能大于10
首先
number == 10
改为
number >= 10
还有万一number>=10并且ten=='X'呢?
所以完整判断:
else if(number>=10){
if((number>=10)&&ten=='X'){
cout<<"Right";
return 0;
}else{
arr[12] = 'X';
printf("%s", arr);
return 0;
}
by _Hu_Tao @ 2022-09-09 17:54:08
@HJRBill 求关注QAQ
by zhang_kevin @ 2022-09-09 17:59:13
@_Hu_Tao 帮助别人是为了得到关注?
by _Hu_Tao @ 2022-09-09 18:04:38
@zhang_kevin 是求关注,没有强迫
by HJRBill @ 2022-09-09 20:27:56
@VecTest 谢谢大佬指点
by HJRBill @ 2022-09-09 20:36:02
@_Hu_Tao 谢谢大佬,关注了,我确实忽略了arr[12]='X',不过number不能大于10哦,因为我前面使用了%11 所以其实这么改就行了,多谢大佬指点
else if (number >= 10)
{
if (ten + '0' == 'X')
{
printf("Right");
}
else
{
arr[12] = 'X';
printf("%s", arr);
}
}