hututu1552727739 @ 2023-04-04 22:13:28
#include<iostream>
#include<string>
using namespace std;
main()
{
string a;;
int i,mod,sum=0,k=0;
cin>>a;
for(i=0;i<13;i++)
{
if(a[i]!='-')
{
k++;
sum+=k*(a[i]-'0');
}
}
mod=sum%11;
if(mod==a[13])
cout<<"Right";
else if(mod!=a[13])
{
if(mod==10)
{
a[13]='X';
}
else
{
a[13]=mod+'0';
}
cout<<a;
}
}
by manyc @ 2023-04-05 12:47:02
@hututu1552727739 我只知道循环容易出问题,不如直接用数组位置,通俗点讲就是我懒得看,ACcode:
#include<iostream>
using namespace std;
int main(){
char s[14],c;
cin>>s;
int h=0,k=0;
for(int i=0;i<11;i++){
if(s[i]!='-'){
k++;
h+=k*(s[i]-'0');
}
}
h%=11;
if(h==10) c='X';
else c=h+'0';
if(c==s[12]) cout<<"Right";
else{
s[12]=c;
cout<<s;
}
return 0;
}