summer_2022 @ 2023-08-28 14:27:06
代码如下
#include<stdio.h>
#include<string.h>
int main()
{
char str[13];
char truely[13];
int flag=0,num=1;
scanf("%s",str);
strcpy(truely,str);
for (int i=0;i<12;++i){
if(str[i]=='-')
continue;
flag=flag+(str[i]-'0')*num;
num++;
}
if(flag%11==10)
truely[12]='X';
else
truely[12]=flag%11+'0';
if(strcmp(str,truely)!=0)
{
printf("%s",truely);
}else
printf("Right");
return 0;
}
by zcy_jake @ 2023-08-28 19:34:42
@summer_2022
直接拿万能头,string 类型就好了,没必要那么麻烦。
#include<bits/stdc++.h>
using namespace std;
int main(){
string str,truely;
int flag=0,num=1;
cin>>str;
truely=str;
for (int i=0;i<12;++i){
if(str[i]=='-')continue;
flag=flag+(str[i]-'0')*num;
num++;
}
if(flag%11==10)
truely[12]='X';
else
truely[12]=flag%11+'0';
if(str!=truely){
cout<<truely<<endl;
}else printf("Right");
return 0;
}
求关(QWQ)