qibai274 @ 2023-08-26 23:52:20
已经考虑了X的情况
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
using namespace std;
int main(){
long long int lan,pub,num,id;
scanf("%lld-%lld-%lld-%lld",&lan,&pub,&num,&id);
int cal[9];
cal[0]=lan;
int pub1 =pub;
for(int i=3;i>=1;i--){
cal[i] = pub%10;
pub = pub/10;
}
int num1=num;
for(int i=8;i>=4;i--){
cal[i] = num%10;
num = num/10;
}
int t=0;
for(int i=0;i<9;i++){
t = t+(i+1)*cal[i];
}
int mod = t%11;
string sid = to_string(id);
if(id==30){ //X读入是30
id = 10;
}
if(id==mod){
cout<<"Right";
}
//1-670-92162-4
else{
cout<<lan<<"-";
for(int i=1;i<=3;i++){
cout<<cal[i];
}
cout<<"-";
for(int i=4;i<=8;i++){
cout<<cal[i];
}
if(mod==10){
cout<<"-X";
}
else{
cout<<"-"<<mod;
}
}
}
by zcy_jake @ 2023-08-27 09:05:37
@qibai274
这是我的程序,更简洁明了:
#include<bits/stdc++.h>
using namespace std;
string a;
int sum,k,ans;
char ansc;
int main() {
cin>>a;
for(int i=0;i<a.size()-2;i++){
if(a[i]!='-'){
k++;
sum+=(a[i]-'0')*k;
}
}
sum%=11;
if(sum==10)ansc='X';
else ansc=sum+'0';
if(a[12]==ansc)cout<<"Right"<<endl;
else{
for(int i=0;i<a.size()-1;i++)cout<<a[i];
cout<<ansc<<endl;
}
}
求关(QWQ)