Redl1ght_S @ 2023-10-10 21:36:26
#include<bits/stdc++.h>
using namespace std;
string s;
int ctoi(char a){ int b = a - '0'; return b; }
int solve(void){ int nowdigit = 1; long long modSum = 0; for(char c : s){ if(c == '-'){ continue; }else{ modSum += nowdigit * ctoi(c); nowdigit++; if(nowdigit > 9){ return modSum % 11; } } } return 0; }
int main(){ stringstream ansISBN; cin >> s; int ID = solve(); for(int i=1; i<=13; i++){ if(i == 13){ if(s[i-1] == ID){ cout << "Right" << endl; }else if(s[i-1] == 'X' && ID == 10){ cout << "Right" << endl; }else{ cout << ansISBN.str() << ID << endl; } }else{ ansISBN << s[i-1]; } } return 0; }
by Redl1ght_S @ 2023-10-10 21:44:57
#include<bits/stdc++.h>
using namespace std;
string s;
int ctoi(char a){
int b = a - '0'; // b = 1;
return b;
}
int solve(void){
int nowdigit = 1;
long long modSum = 0;
for(char c : s){
if(c == '-'){
continue;
}else{
modSum += nowdigit * ctoi(c);
nowdigit++;
if(nowdigit > 9){
return modSum % 11;
}
}
}
return 0;
}
int main(){
stringstream ansISBN;
cin >> s;
int ID = solve();
if(s[12] == ID || (s[12] == 'X' && ID == 10)){
cout << "Right" << endl;
}else{
for(int i=1; i<=12; i++){
if(i == 12){
cout << ansISBN.str() << "-" << ID << endl;
return 0;
}
ansISBN << s[i-1];
}
}
}
改成这个b样子