slry666 @ 2022-08-20 09:23:48
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
long long j,len,i,sum;
string s,a;
int main(){
cin>>s;
len=s.length();
j=1;
for(i=0;i<len-1;i++) {
if(s[i]=='-')
continue;
sum+=(s[i]-'0')*j;
j++;
}
int t=sum%11;
if(t==10) t='X';
else if(t+'0'==s[len-1]) cout<<"Right";
else{
s[len-1]=t+'0';
cout<<s;
}
}
by _Haoomff_ @ 2022-08-20 09:29:10
@slry666 t是整形赋值‘X’?
by _Healer @ 2022-08-20 09:33:42
@slry666
改成这样:
#include<bits/stdc++.h>
using namespace std;
long long j,len,i,sum;
string s,a;
signed main()
{
cin>>s;
len=s.length();
j=1;
for(i=0;i<len-1;i++)
{
if(s[i]=='-') continue;
sum+=(s[i]-'0')*j; j++;
}
int t=sum%11;
char ch;
if(t==10) ch='X';
else ch=t+'0';
if(ch==s[len-1]) cout<<"Right";
else{ s[len-1]=ch; cout<<s; }
return 0;
}
by slry666 @ 2022-08-20 09:35:35
谢谢,已AC