jiang123478 @ 2024-11-28 20:08:27
一直有两个检查点过不去,代码比较粗暴,懒得用循环了 谢谢各位前辈
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a,b,c,d,e,f,g,h,i,j;
scanf("%c-%c%c%c-%c%c%c%c%c-%c",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
int sum;
sum=(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;
if(sum%11==j-'0')
{
printf("Right");
}
else if(sum%11==10)
{
printf("%c-%c%c%c-%c%c%c%c%c-X",a,b,c,d,e,f,g,h,i);
}
else
{
printf("%c-%c%c%c-%c%c%c%c%c-%d",a,b,c,d,e,f,g,h,i,sum%11);
}
}
by myh121127 @ 2024-12-02 17:12:50
@jiang123478
#include<bits/stdc++.h>
using namespace std;
int main(){
char a[15];
cin>>a;
int c=0,x=1;
for(int i=0;i<11;i++){
if(a[i]>='0'&&a[i]<='9'){
c=c+x*(a[i]-'0');
x++;
}
}
if(c%11==a[12]-'0'||(c%11==10&&a[12]=='X')){
cout<<"Right";
return 0;
}else{
for(int i=0;i<11;i++){
cout<<a[i];
}
cout<<'-';
if(c%11==10){
cout<<'X';
return 0;
}
cout<<c%11;
}
return 0;
}
题目不难
你忘记特判sum%11=10检验码输出X了