fw999999999999 @ 2024-12-01 11:42:14
#include<iostream>
#include<string>
using namespace std;
int main()
{
char ISBN[14];
char a;
cin >> ISBN;
int k = 1;
int sum = 0;
for (int i = 0; i < 11; i++)
{
if (ISBN[i]!='-')
{
sum += k * (ISBN[i] - '0');
k++;
}
}
char c = sum % 11+'0';
if (c == '10')
{
c = 'X';
}
if (ISBN[12] == c)
{
cout << "Right" << endl;
}
else
{
ISBN[12] = c;
cout << ISBN << endl;
}
return 0;
}
by nemo121018 @ 2024-12-01 20:15:55
@fw999999999999
#include<iostream>
#include<string>
using namespace std;
int main()
{
char ISBN[14];
char a;
cin >> ISBN;
int k = 1;
int sum = 0;
for (int i = 0; i < 12; i++)
{
if (ISBN[i]!='-')
{
sum += k * (ISBN[i] - '0');
k++;
}
}
int c = sum % 11;
if (ISBN[12]=='X'&&c == 10)
{
cout << "Right" << endl;
return 0;
}
if ((ISBN[12]-'0') == c)
{
cout << "Right" << endl;
return 0;
}
else
{
for(int i=0;i<12;i++)
{
cout<<ISBN[i];
}
if(c==10)
{
cout<<"X";
}
else
{
cout<<c;
}
}
return 0;
}
by nemo121018 @ 2024-12-01 20:44:12
可以这样试试看