Hayward @ 2022-11-30 09:54:43
#include<iostream>
#include<string>
using namespace std;
int main()
{
char c[13]{};
int x = 0;//
int temp = 0;
for (int i = 0; i < 13; i++)
{
cin >> c[i];
if (c[i]=='X')
{
c[i] = 10;
}
}
for (int i = 0; i < 12; i++)
{
if (c[i] != '-')
{
x++;
temp+= (c[i] - '0') * x;//'0'就是48,char类型运算时会变更为阿斯克码
//cout << temp << endl;
}
}
int a=c[12]-48;
if (temp % 11 == a)
{
cout << "Right";
return 0;
}
else
{
int b = temp % 11;
//c[12] = temp % 11;
for (int i = 0; i < 12; i++)
{
cout << c[i];
}
cout << b;
}
}
by Feng_Jing @ 2022-11-30 09:59:27
@Hayward
return 0;
by The_Wandering_Earth @ 2022-11-30 10:03:51
#include<bits/stdc++.h>
using namespace std;
int main(){
char a[14],b[11]={'0','1','2','3','4','5','6','7','8','9','X'};
scanf("%s",a);
int j=1,t=0;
for(int i=0;i<12;i++){
if(a[i]=='-') continue;
t+=(a[i]-48)*j++;
}
t%=11;
if(b[t]==a[12]){
cout<<"Right";
}
else{
a[12]=b[t];
printf("%s",a);
}
}
@Hayward 你看一下我这个代码,理解一下,不明白的私信跟我说
by TLE_AK @ 2022-11-30 10:23:26
@Hayward 你好像没特判识别码应为X的情况
input:0-500-00000-2
output:0-500-00000-X
你的答案:0-500-00000-10
by TLE_AK @ 2022-11-30 10:31:03
@TLE_AK 还有个hack:
input:0-500-00000-X
output:Right
你的答案:0-500-00000-10