nahida_badminton @ 2023-07-30 21:16:43
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
int isbn[10];
char ma;
scanf("%d-%d%d%d-%d%d%d%d%d-%c", &isbn[0], &isbn[1], &isbn[2], &isbn[3], &isbn[4], &isbn[5], &isbn[6], &isbn[7], &isbn[8], &ma);
int sum;
for (int i = 1; i <= 10; i++){
sum += isbn[i-1] * i;
}
int a = sum % 11;
if (ma == 'X' && a == 10){
cout << "Right";
} else if (ma - '0' == a){
cout << "Right";
} else {
printf("%d-%d%d%d-%d%d%d%d%d-%d", &isbn[0], &isbn[1], &isbn[2], &isbn[3], &isbn[4], &isbn[5], &isbn[6], &isbn[7], &isbn[8], &a);
}
return 0;
}
//忽略我这超嗷嗷嗷嗷极长的输入输出吧我实在想不出别的办法了
我在Dev上逝了世然后输出了一大堆乱码……
0-670-82162-4
7470560-747056474705687470572-74705767470580747058474705887470592-7470608
希望哪位大佬能帮一下我谢谢!!!
by lvzekai @ 2023-07-30 21:25:58
@nahida_badminton
int a = sum % 11;
if (ma == 'X' && a == 10){
cout << "Right";
} else if (ma - '0' == a){
cout << "Right";
} else {
printf("%d-%d%d%d-%d%d%d%d%d-%d", &isbn[0], &isbn[1], &isbn[2], &isbn[3], &isbn[4], &isbn[5], &isbn[6], &isbn[7], &isbn[8], &a);
}
你的判断错了
by nahida_badminton @ 2023-07-30 21:33:47
@lvzekai 大佬,是第几个判断啊
by lvzekai @ 2023-07-30 21:41:14
@nahida_badminton 你可以看看我的代码
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,s,ans=1;
string a;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>a;
n=a.size()-1;
for(int i=0;i<n;i++)
{
if(a[i]>='0'&&a[i]<='9')
{
s=s+(a[i]-'0')*ans;
ans++;
s%=11;
}
}
if((a[n]-'0'==s)||(a[a.size()-1]=='X'&&s==10))
{
cout<<"Right"<<"\n";
}
else
{
for(int i=0;i<n;i++)
{
cout<<a[i];
}
if(s==10)
{
cout<<"X"<<"\n";
}
else
{
cout<<s<<"\n";
}
}
return 0;
}
by nahida_badminton @ 2023-07-30 22:22:24
谢谢大佬,我发现问题了,是在输入的时候忘记声明域宽了