wxr0108 @ 2022-09-19 22:24:39
#include<bits/stdc++.h>
using namespace std;
int main(){
int ans=1,cnt=0;
char s[3000];
cin>>s;
int len=strlen(s);
for(int i=0;i<len-1;i++){
if(s[i]!='-'){
int t=s[i]-'0';
cnt+=(ans*t);
ans++;
}
}
//cout<<ans<<endl;
int w=cnt%11;
if((s[len-1]-'0')==w){
cout<<"Right\n";
return 0;
}else{
for(int i=0;i<len-1;i++) cout<<s[i];
}
cout<<w<<endl;
return 0;
}
by zhangjingxing2012 @ 2022-09-21 17:46:56
奉上O(1)代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a,b,c,d,e,f,g,h,i,j;
int check;
scanf("%c-%c%c%c-%c%c%c%c%c-%c",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
check=(a-'0')*1+(b-'0')*2+(c-'0')*3+(d-'0')*4+(e-'0')*5
+(f-'0')*6+(g-'0')*7+(h-'0')*8+(i-'0')*9;
check%=11;
if(j=='X'&&check==10||check==j-'0') printf("Right");
else printf("%c-%c%c%c-%c%c%c%c%c-%c",a,b,c,d,e,f,g,h,i,check==10?'X':check+'0');
}