Enjoy_it @ 2022-02-09 18:50:46
为啥数组的长度写14就对,写13就错,长度不就该是13吗?我数错了吗?
#include<stdio.h>
int main(){
char s[14],c;int p = 0,j=1;
scanf("%s",s);
p = ((s[0]-'0')*1+(s[2]-'0')*2+(s[3]-'0')*3+(s[4]-'0')*4+(s[6]-'0')*5+(s[7]-'0')*6+(s[8]-'0')*7+(s[9]-'0')*8+(s[10]-'0')*9)%11;
if(p == s[12]-'0'||(p==10&&s[12]=='X')){
printf("Right");
}else{
if(p == 10){
s[12] = 'X';
}else{
s[12] = p+'0';
}
printf("%s",s);
}
return 0;
}
by w23c3c3 @ 2022-02-09 18:52:28
有一位留给表示结束的字符 '\0'
。
by loverintime @ 2022-02-09 18:53:34
最后会有一个 '\0'
by ssxvngn @ 2022-02-09 18:55:08
@Enjoy_it 13能过啊??
by Enjoy_it @ 2022-02-09 21:20:19
@一个pupil 我的一直过不了,改为14就过了
by Enjoy_it @ 2022-02-09 21:20:54
@w23c3c3 哦哦,明白了,谢了
by Enjoy_it @ 2022-02-09 21:21:17
@xby070301 明白了,谢谢
by ssxvngn @ 2022-02-09 21:32:48
@Enjoy_it 是吗?可能因为我用的是c++14吧