queshibuhui @ 2021-12-28 16:00:03
#include<stdio.h>
int main() {
char c[14];
scanf("%s", c);
char a;
int sum = 0;
int j = 1;
for (int i = 0; i < 12; i++) {
if ((a = c[i]) == '-')continue;
sum = sum + (a - '0') * j++;
}
sum = sum % 11;
if (c[12] - '0' == sum)printf("Right");
else {
if (sum == 10)c[12] = 'X';
else c[12] = sum + '0';
printf("%s", c);
}
}
by queshibuhui @ 2021-12-28 16:00:45
第四个过不去好奇怪
by dzn123456 @ 2021-12-28 16:54:42
哥,当最后一位为‘X'时,如果正确,sum%11==10,但c[12]-48=='X'-48!=10 改成这样
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int b=0,a[10],sum=0;
char s[20];
for(int i=0;i<13;i++) cin>>s[i];
for(int i=0;i<13;i++)
{
if(s[i]!='-')
{
if(s[i]!='X')
a[b]=s[i]-48;
else
a[b]='X'-48;
b++;
}
}
for(int i=1;i<=9;i++) sum+=a[i-1]*i;
if(sum%11==a[9]) cout<<"Right";
else
if(sum%11==10&&a[9]=='X'-48)
cout<<"Right";
else
{
for(int i=0;i<12;i++) cout<<s[i];
if(sum%11==10) cout<<"X";
else cout<<sum%11;
}
}
iii,bye!~