xfit @ 2024-10-11 09:58:54
global num_last
def isRight(id_ISBN):
global num_last
id_num = '' + id_ISBN[0] + id_ISBN[2:5] + id_ISBN[6:11]
num_last = sum(int(id_num[i]) * (i + 1) for i in range(len(id_num))) % 11
if num_last == 10 and id_ISBN[12] == 'X':
return True
elif num_last == int(id_ISBN[12]):
return True
else:
return False
if __name__ == "__main__":
id_ISBN = input()
if isRight(id_ISBN):
print("Right")
else:
if num_last == 10:
num_last = 'X'
id_ISBN_new = id_ISBN[:12] + str(num_last)
print(id_ISBN_new)
by abssortpow1145145 @ 2024-10-11 20:26:46
AC代码求关
#include <bits/stdc++.h>
using namespace std;
int main()
{
string a;
cin >> a;
int len=a.size(),cnt=1,sum=0;
for(int i=0;i<=10;i++)
{
if(a[i]>=48 && a[i]<=57)
{
int k=a[i]-48;
sum+=k*cnt;
cnt++;
}
}
sum%=11;
char c;
if(sum==10)
{
c='X';
}
else
{
c=sum+48;
}
if(c==a[12])
{
cout << "Right";
}
else
{
a[12]=c;
cout << a;
}
return 0;
}