Coffee_Moew @ 2023-08-01 10:32:16
WA了#5,#6,#9,代码如下:
#include<bits/stdc++.h>
using namespace std;
int main()
{
string isbn;
int sbm,sl=1;
cin>>isbn;
for(int i=0;i<isbn.size()-1;i++)
if(isbn[i]!='-')
{
sbm=sbm+(isbn[i]-'0')*sl;
sl++;
}
sbm=sbm%11;
if(isbn[isbn.size()-1]-'0'==sbm||(isbn[isbn.size()-1]=='X'&&sbm==10)) cout<<"Right";
else
{
for(int i=0;i<isbn.size()-1;i++) cout<<isbn[i];
cout<<sbm;
}
return 0;
}
by ForgotDream_CHN @ 2023-08-01 10:42:01
@Coffee_Moew 最后要判断一下 sdm == 10
by ForgotDream_CHN @ 2023-08-01 10:49:31
@Coffee_Moew
还有 sbm
要初始化
#include<bits/stdc++.h>
using namespace std;
int main()
{
string isbn;
int sbm = 0,sl=1;
cin>>isbn;
for(int i=0;i<isbn.size()-1;i++)
if(isbn[i]!='-')
{
sbm=sbm+(isbn[i]-'0')*sl;
sl++;
}
sbm=sbm%11;
if(isbn[isbn.size()-1]-'0'==sbm||(isbn[isbn.size()-1]=='X'&&sbm==10)) cout<<"Right";
else
{
for(int i=0;i<isbn.size()-1;i++) cout<<isbn[i];
cout<<(sbm == 10 ? (char)'X' : char(sbm + '0'));
}
return 0;
}
by Coffee_Moew @ 2023-08-01 10:55:35
@ForgotDream_CHN 谢大佬,已关