kc0205 @ 2022-03-17 18:45:42
#include<bits/stdc++.h>
using namespace std;
int main(){
string n;
int sum = 0;
cin >> n;
int j = 0;
for(int i = 1;i < 13;i++){
if(n[j] == '-'){
continue;
}
sum += (n[j] * i);
j++;
}
sum %= 11;
if(sum == 10){
sum = 'X';
}
if(sum == 'X' && sum == n[12]){
cout << "Right";
}else if(sum == (n[12] - '0')){
cout << "Right";
}else if(sum == 'X'){
for(int i = 0;i < 12;i++){
cout << n[i];
}
cout << 'X';
}else{
for(int i = 0;i < 12;i++){
cout << n[i];
}
cout << sum;
}
return 0;
}
by Yyds0916 @ 2022-03-17 18:48:17
for循环处不对
for(int i=0;i<11;i++)
{
if(s[i]!='-')
{
k++;
h+=k*(s[i]-'0');
}
}
下面是我的代码
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char s[14],c;
cin>>s;
int h=0,k=0;
for(int i=0;i<11;i++)
{
if(s[i]!='-')
{
k++;
h+=k*(s[i]-'0');
}
}
h%=11;
if(h==10) c='X';
else c=h+'0';
if(c==s[12]) cout<<"Right"<<endl;
else
{
s[12]=c;
cout<<s;
}
return 0;
}
by kc0205 @ 2022-03-17 20:45:36
谢谢