yangdoubao @ 2021-12-01 18:46:58
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
int ans=0;
int main()
{
char s[13];
char r[12]="0123456789X";
char i[10]={'X'};
cin>>s;
int t=1;
for(int i=0;i<12;i++)
{
if(s[i]!='-')
{
int cache=s[i]-'0';
ans+=cache*t;
t+=1;
}
}
ans%=11;
if(s[12]==r[ans]) cout<<"Right";
else {s[12]=r[ans];cout<<s;}
return 0;
}
有没有大佬知道为啥输出的时候最后会多一个空格?求助
by Mary_mzxx @ 2021-12-06 20:23:09
#include<iostream>
#include<cstring>
using namespace std;
char s[14],c;
int main(){
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;
}