apple_up @ 2022-10-12 19:01:41
#include <stdio.h>
int main()
{
char str[100], pan;
long int b[100], c[100], sum = 0, x;
scanf("%s", str);
pan = str[12];
getchar();
for (int i = 0, j = 0; i < 9; i++, j++)
{
if (j != 1 && j != 5)
{
b[i] = str[i] - '0';
}
else
{
i--;
}
}
for (int i = 0; i < 9; i++)
{
sum += (i + 1) * b[i];
}
str[12] = '\0';
x = sum % 11;
if ((x == 10 && pan == 'X') || (x < 10 && x == pan - 48))
{
printf("Right");
}
else
{
printf("%s", str);
if (x == 10)
{
printf("X");
}
else
printf("%d", x);
}
}
by ryf_loser @ 2022-10-12 19:08:46
@fewaf
#include<bits/stdc++.h>
using namespace std;
int s;
char a[15];
int main(){
for (int i=1;i<=13;i++)
scanf ("%c",&a[i]);
for (int i=1,j=1;i<=11;i++){
if (a[i]=='-')continue;
s+=(a[i]-'0')*j;
j++;
}
s%=11;
if (s==10)s='X';
if (s==a[13]-'0'||s==a[13])
printf ("Right");
else
{
for (int i=1;i<=12;i++){
printf ("%c",a[i]);
}
if (s=='X')
printf ("X");
else
printf ("%d",s);
}
return 0;
}
我的代码
by Ricky2008 @ 2022-10-12 19:15:43
@fewaf
#include<bits/stdc++.h>
using namespace std;
int main(){
int a[5],b,c,d,e,f,sum=0;
cin>>a[1];
getchar();
cin>>a[2];
getchar();
cin>>a[3];
getchar();
if(scanf("%d",&a[4])!=1)a[4]=10;
sum+=a[1];
b=a[2]/100;
c=(a[2]/10)%10;
d=a[2]%10;
sum=sum+b*2+c*3+d*4;
b=a[3]/10000;
c=(a[3]/1000)%10;
d=(a[3]/100)%10;
e=(a[3]/10)%10;
f=a[3]%10;
sum=sum+b*5+c*6+d*7+e*8+f*9;
sum=sum%11;
if(sum==a[4])cout<<"Right";
else{if(sum!=10) printf("%d-%d-%d-%d",a[1],a[2],a[3],sum);
else printf("%d-%d-%d-X",a[1],a[2],a[3]);
}
return 0;
}
by __er @ 2022-10-12 19:36:56
人家是C,你们发个C++的……
by yanxu_cn @ 2022-10-12 19:59:02
str[i]
应该为 str[j]
才对