XnLemon @ 2023-11-04 20:42:04
#include<stdio.h>
int main(){
int a,b,c,d,a_1,b_1,c_1;
int arr_b[3]={0};
int arr_c[5]={0};
int i,v,re_c,result,m,n;
int d_final,c_final,b_final;
c_final = 0;
b_final = 0;
scanf("%d-%d-%d-%c",&a,&b,&c,&d);
if (d == 88)
{
d = 10;
}
else
{
d = d - 48;
}
a_1 = a;
b_1 = b;
c_1 = c;
for(i=0;i<3;i++){
result = b % 10;
arr_b[i] = result;
b = b / 10;
}
for(v=0;v<5;v++){
re_c = c % 10;
arr_c[v] = re_c;
c = c / 10;
}
for(m=2;m<=4;m++){
b_final = b_final + arr_b[(4-m)]*m;
}
for(n=5;n<=9;n++){
c_final = c_final + arr_c[(9-n)]*n;
}
d_final = (a + b_final + c_final) % 11;
if(d_final == d){
printf("Right");
}
else{
if(d_final == 10){
d = 88;
printf("%d-%d-%d-%c",a_1,b_1,c_1,d);
}
else{
printf("%d-%d-%d-%d",a_1,b_1,c_1,d_final);
}
}
}
第一个测试点输入的是样例1 输出应该是Right 本地跑过了输出确实是Right 但是测试点不给过 并且其他的测试点错的都是想要让程序输出Right 求救xwx
by ink114514 @ 2023-11-06 22:51:24
代码的网址:https://www.luogu.com.cn/problem/P1055#submit
by hytdy @ 2023-11-11 16:19:45
同问
by Azzero @ 2023-12-01 11:55:21
问题在这段对字符变量d的比较赋值里面,d是一个字符变量,肯定跟一个数值常量是不相等的,
scanf("%d-%d-%d-%c",&a,&b,&c,&d);
if (d == 88)
{
d = 10;
}
else
{
d = d - 48;
}
应该是
int num_d=0; //用来存最后以为字符的数值量
if(d == 'X'){
num_d=10; //如果最后以为是X,保存10;
}else{
num_d=d-'0'; //其他保存数值本身
]
你这一步对d判断,赋值错了,后面的跟取余的结果比较,肯定还是错的,所以永远不会输出Right
by Azzero @ 2023-12-01 11:56:31
@hytdy 钟离老爷子,回复来了,感觉你应该已经想出来了吧
by XnLemon @ 2023-12-04 20:11:19
@Azzero 感谢