ch11m5 @ 2022-10-06 20:38:58
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d;
int sum1,sum2,sum,y;
scanf("%d-%d-%d-%d",&a,&b,&c,&d);
sum1=a*1+(b/100)*2+((b%100)/10)*3+(b%10)*4;
sum2=(c/10000)*5+((c%10000)/1000)*6+((c%1000)/100)*7+((c%100)/10)*8+(c%10)*9;
sum=sum1+sum2;
y=sum%11;
if(y==d)
{
cout<<"right"<<endl;
}
else
{
printf("%d-%d-%d-%d",a,b,c,y);
}
return 0;
}
by 07kzs @ 2022-10-06 21:20:43
1.输出应为“Right”,r要大写。
2.输入的d(最后一位识别码)应为char类型,d可能为X。
3.输出正确的ISBN号码时,应特判识别码(最后一个字符)为X的情况。
by 07kzs @ 2022-10-06 21:21:57
@ch11m5
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c;
char d;
int sum1,sum2,sum,y;
scanf("%d-%d-%d-%c",&a,&b,&c,&d);
sum1=a*1+(b/100)*2+((b%100)/10)*3+(b%10)*4;
sum2=(c/10000)*5+((c%10000)/1000)*6+((c%1000)/100)*7+((c%100)/10)*8+(c%10)*9;
sum=sum1+sum2;
y=sum%11;
if(y==d-'0'||(y==10&&d=='X')) {
cout<<"Right";
}else{
if(y==10) printf("%d-%d-%d-X",a,b,c);
else printf("%d-%d-%d-%d",a,b,c,y);
}
return 0;
}
by ch11m5 @ 2022-10-08 16:21:39
@07kzs 谢谢 QAQ