XiMeng_2077 @ 2023-08-01 22:23:17
代码写的有点乱,还请包涵
测试点#4 #7没过,在线等大佬解答
#include<bits/stdc++.h>
using namespace std;
int main(){
char ch[15];int a[15]={0};
int temp=0;int ans=0;int np=1;
for(int i=1;i<=13;i++){
scanf("%c",&ch[i]);
}
for(int i=1;i<=13;i++){
temp=int(ch[i]);
if(temp!=45){
a[np]=temp-48;
np++;
}
}
for(int i=1;i<=9;i++){
ans=ans+a[i]*i;
}
if(ans%11==a[10]){
cout<<"Right";
return 0;
}else{
for(int i=1;i<=12;i++){
printf("%c",ch[i]);
}
if(ans%11==10){
cout<<"X";
}else{
cout<<ans%11;
}
}
return 0;
}
by XiMeng_2077 @ 2023-08-01 22:48:51
解决了没有考虑到识别码为本来就为X的情况,谢谢大佬
if(ans%11==a[10]||(ans%11==10&&ch[13]=='X')){
cout<<"Right";
return 0;
by zhanghe724_1 @ 2023-08-04 14:58:38
#include<iostream>
#include<cstring>
using namespace std;
int main(){
string a;
cin>>a;
int s=(a[0]-'0')*1+(a[2]-'0')*2+(a[3]-'0')*3+(a[4]-'0')*4+(a[6]-'0')*5+(a[7]-'0')*6+(a[8]-'0')*7+(a[9]-'0')*8+(a[10]-'0')*9;
s%=11;
if(s==10&&a[12]=='X')cout<<"Right";
if(s<10&&s==a[12]-'0')cout<<"Right";
if(s==10&&a[12]!='X'){
a[12]='X';
cout<<a;
}
if(s<10&&s!=a[12]-'0'){
a[12]=s+'0';
cout<<a;
}
}