逍遥瑾柒 @ 2024-10-17 16:06:58
#include<iostream>
#include<string>
using namespace std;
int main(){
string str;
char c[15],num[9];
cin >> str;
str.copy(c,13,0);
*(c+13) = '\0';
int j = 0,k = 0;
while(c[k] != '\0'){
if(c[k] != '-'){
num[j] = c[k];
j++;
k++;
}
else
k++;
}
int a[10], sum;
for(int i =0;i < 9;i++)
a[i] = num[i] - '0';
for(int i =0;i < 9;i++)
sum = sum + a[i] * ( i + 1 );
sum = sum % 11;
if(sum != 10){
if(sum == c[12] - '0')
cout << "Right";
else{
for(int i = 0;i < 12;i++)
cout << c[i];
cout << sum ;}
}
else
{
if(c[12] == 'X')
cout << "Right";
else{
for(int i = 0;i < 12;i++)
cout << c[i];
cout << 'X';}
}
return 0;
}
by wuyusheng @ 2024-10-21 20:28:35
@逍遥瑾柒 AC代码
#include<bits/stdc++.h>
using namespace std;
int main()
{
char a[14],c;
cin>>a;
int b=0,d=0;
for(int i=0;i<11;i++)
{
if(a[i]!='-')
{
d++;
b+=d*(a[i]-'0');
}
}
b%=11;
if(b==10) c='X';
else c=b+'0';
if(c==a[12])
cout<<"Right"<<endl;
else
{
a[12]=c;
cout<<a<<endl;
}
return 0;
}
by plkmnji888 @ 2024-10-22 18:11:42
貌似能用队列
by plkmnji888 @ 2024-10-22 18:13:30
遍历字符串,把从左到右找到的数字按顺序入队,再一个一个弹出计算就行了