Iain_ @ 2024-08-03 22:00:24
#include<bits/stdc++.h>
using namespace std;
int a[15],sum=4;
int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
string s;
cin>>s;
for(int i=0;i<s.size()-2;i++)if(s[i]!='-')a[i]=s[i]-'0';
for(int i=0,j=1;i<s.size();i++,j++)sum+=a[i]*j;
if((sum%11==s[s.size()-1]-'0'&&sum%11!=10)||(sum%11==10&&s[s.size()-1]=='X'))cout<<"Right";
else{
cout<<"0-670-82162-4";
}
return 0;
}
by meifan666 @ 2024-08-03 22:18:08
@Iain_ 改后的ISBN代码要自己算,可能不一样
by Iain_ @ 2024-08-03 22:25:10
@meifan666 什么意思?
by meifan666 @ 2024-08-03 22:34:37
@Iain_ 如果ISBN号不对,你的代码会输出"0-670-82162-4",正确的ISBN一定是它吗?
by Iain_ @ 2024-08-04 18:14:33
@meifan666 不是,我最开始写的是改正,可后面提交了全是WA
by Iain_ @ 2024-08-04 22:35:05
@meifan666 而且,我写了改正后还是40
by meifan666 @ 2024-08-04 22:38:25
@Iain_ 那你为什么只发这种改正前的错误代码,发发最新的呀(无奈)
by meifan666 @ 2024-08-04 22:39:35
@Iain_
参考一下
scanf("%c-%c%c%c-%c%c%c%c%c-%c",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
t=(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;
t%=11;
if(t==10&&j=='X' || t==j-'0')cout<<"Right";
else
{
printf("%c-%c%c%c-%c%c%c%c%c",a,b,c,d,e,f,g,h,i);
if(t==10)cout<<"-X";
else
{
cout<<"-"<<t;
}
}
by Iain_ @ 2024-08-05 17:19:42
@meifan666 h还是不行:
#include<bits/stdc++.h>
using namespace std;
int a[15],sum=4,n;
int main(){
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
string s;
cin>>s;
if(s[s.size()-1]=='X')n=10;else n=s[s.size()-1]-'0';
for(int i=0;i<s.size()-2;i++)if(s[i]!='-')a[i]=s[i]-'0';
for(int i=0,j=1;i<s.size();i++,j++)sum+=a[i]*j;
sum%=11;
if(sum==n)cout<<"Right";
else{
for(int i=0;i<s.size()-1;i++)cout<<s[i];
if(sum=='X')cout<<'X';
else cout<<sum;
}
return 0;
}
by meifan666 @ 2024-08-05 22:04:58
@Iain_ 你看一下我的代码对照一下不就行了(我就不信这都改不出)
by Iain_ @ 2024-08-06 11:32:41
@meifan666 我试过了,按你的也不行