Tudoudidan @ 2024-03-19 19:29:07
#include <bits/stdc++.h>
using namespace std;
int main(){
long long a,b,c,d,e=0,s=0;
char f;
scanf("%d-%d-%d-%c",&a,&b,&c,&f);
e=a*100000000+b*100000+c;
for(int i = 9;i>=0;--i){
s+=(e%10)*i;
e/=10;
}
s=s%11;
if(f-'0'==s||(s==10&&f=='X')){
cout<<"Right";
}
else{
printf("%d-%d-%d-",a,b,c);
cout<<((s==10)?'X':s);
}
return 0;
}
样例也过了,但不知为何就是爆零(T_T) 请教一下各位大神,我的代码出了什么问题
by OutsideR_ @ 2024-03-19 19:32:53
@Tudoudidan 70pts修改
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,e=0,s=0;
char f;
int main(){
scanf("%d-%d-%d-%c",&a,&b,&c,&f);
e=a*100000000+b*100000+c;
for(int i = 9;i>=0;--i){
s+=(e%10)*i;
e/=10;
}
s=s%11;
if(f-'0'==s||(s==10&&f=='X')){
cout<<"Right"<<endl;
return 0;
}
else{
printf("%d-%d-%d-",a,b,c);
cout<<((s==10)?'X':s);
}
return 0;
}
问题:scanf不好用%d输入long long且 long long定义在主函数内会随机赋值
by Tudoudidan @ 2024-03-19 19:36:37
@OutsideR_ 多谢大佬
by OutsideR_ @ 2024-03-19 19:41:08
@Tudoudidan
#include <bits/stdc++.h>
using namespace std;
int a,b,c,d,e=0,s=0;
char f;
int main(){
scanf("%d-%d-%d-%c",&a,&b,&c,&f);
e=a*100000000+b*100000+c;
for(int i=9;i>=0;i--){
s+=(e%10)*i;
e/=10;
}
s=s%11;
if(f-'0'==s||(s==10 &&f=='X')){
cout<<"Right"<<endl;
return 0;
}
else{
printf("%d-%d-%d-",a,b,c);
//比较这一段改了就对了
if(s==10){
cout<<'X'<<endl;
return 0;
}
cout<<s<<endl;
return 0;
}
return 0;
}
by Tudoudidan @ 2024-03-19 19:44:30
@OutsideR_ 多谢大佬帮助