Zjc20120331 @ 2022-12-30 14:27:05
tp
//P1055 [NOIP2008 普及组] ISBN 号码
//2022/12/30 by Zjc20120331
//13:18 V1.0
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int sum = 0;
int j = 1;
for (int i = 0; i < s.size(); i++){
if (s[i] != '-'){
sum += (s[i]-'0')*j;
j++;
}
}
string mod = "0123456789X";
if (mod[sum%11] == s[12]){
cout << "Right";
}else{
s[12] = mod[sum%11];
cout << s;
}
return 0;
}
by Zjc20120331 @ 2022-12-30 14:39:03
不行
//P1055 [NOIP2008 普及组] ISBN 号码
//2022/12/30 by Zjc20120331
//13:18 V1.0
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int sum = 0;
int j = 0;
for (int i = 0; i < s.size(); i++){
if (s[i] != '-'){
sum += (s[i]-'0')*j;
j++;
}
}
string mod = "0123456789X";
if (mod[sum%11] == s[12]){
cout << "Right";
}else{
s[12] = mod[sum%11];
cout << s;
}
return 0;
}
by xueyuhui917 @ 2022-12-30 14:44:23
@planet_over_for_ever 我不太赞同你的想法。
我在代码中 sum += (s[i]-'0')*j;
前面,也就是第 cout<<i<<" "<<j<<"\n";
,输入第一个样例 0-670-82162-4
,输出如下:
0 1
2 2
3 3
4 4
6 5
7 6
8 7
9 8
10 9
12 10
0-670-82162-0
可以看到,@Zjc20120331 把最后一位识别码也算入 sum
里了,导致结果出错。只要把第 i < s.size()
改成 i < 12
就可以了。
by ZQIN_P @ 2022-12-30 14:45:53
@xueyuhui917 咳咳我瞎了
by Zjc20120331 @ 2022-12-30 14:53:09
ok了