LHX_18460366315 @ 2023-12-30 20:57:13
这题只得80分,4/7点错了,代码如下,不知道哪里错了,请大佬帮我改一下:
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
int num = 0;
cin >> a;
num = (a[0]-48) * 1 + (a[2]-48) * 2 + (a[3]-48) * 3 + (a[4]-48) * 4 + (a[6]-48) * 5 + (a[7]-48) * 6 + (a[8]-48) * 7 + (a[9]-48) * 8 + (a[10]-48) * 9;
if (num % 11 == int(a[12] - 48) || num % 11 == int(a[12] - 79)){
cout << "Right";
}else{
for (int i = 0;i < 12;i++){
cout << a[i];
}
if (num % 11 == 10){
cout << "X";
}else{
cout << num % 11;
}
}
return 0;
}
by YRCTTT @ 2024-01-06 10:11:00
#include<iostream>
using namespace std;
int main()
{
string s;
cin>>s;
int sum=0;
int cnt=0;
int i;
for(i=0;i<s.length()&&cnt<9;i++)
{
if(s[i]!='-')
{
sum+=(s[i]-'0')*++cnt;
}
}
char c=sum%11+'0';
if(c>'9')c='X';
if(s[s.size()-1]==c)
{
cout<<"Right"<<endl;
return 0;
}
else
{
s[s.size()-1]=c;
cout<<s;
}
}
X的ASCII值等于88,88-79=9,就没有判出X来。
by YRCTTT @ 2024-01-06 10:12:15
这是我的参考代码 对照下