wcx_is_god @ 2024-04-16 20:16:20
样例都不对,求dalao改一下,请看代码(写的很烂)
#include <bits/stdc++.h>
using namespace std;
char isbn[20];
int s = 0;
int main(){
for(int i = 1; i <= 13; i++){
cin >> isbn[i];
}
s+=int(isbn[1])*1;
s+=int(isbn[3])*2;
s+=int(isbn[4])*3;
s+=int(isbn[5])*4;
s+=int(isbn[7])*5;
s+=int(isbn[8])*6;
s+=int(isbn[9])*7;
s+=int(isbn[10])*8;
s+=int(isbn[11])*9;
cout<<s<<endl;
if(s % 11 == int(isbn[13])){
cout << "Right";
}else{
for(int i = 1; i <= 12; i++){
cout << isbn[i];
}
if(s % 11 == 10) cout << "X";
else cout << s % 11;
}
return 0;
}
by philip2011 @ 2024-04-16 20:19:53
如此即可
#include<bits/stdc++.h>
using namespace std;
char a[14];
long long ans;
int b,len,temp,t=1;
int main()
{
cin.getline(a,14);
len=strlen(a);
for(int i=0;i<len-2;i++){
if(a[i]!='-'){
temp=a[i]-'0';
b+=temp*t;
t++;
}
}
b%=11;
if(b!=10){
if(a[len-1]-'0'==b) cout<<"Right";
else{
for(int i=0;i<len-1;i++) cout<<a[i];
cout<<b;
}
}
else{
if(a[len-1]=='X') cout<<"Right";
else{
for(int i=0;i<len-1;i++) cout<<a[i];
cout<<'X';
}
}
return 0;
}