题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
http://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
#include<stdio.h>
int main() {
int ch[10], sum = 0, rem = 0;
for (int i = 0; i < 10; i++) {
scanf("%1d", &ch[i]);
if (ch[i] < 10) {
if (i == 0 || i == 3 || i == 8) scanf("-");
if (i != 9) sum += ch[i] * (i + 1); //计算数字和
}
if (ch[9] % 10 == 0) ch[9] = 10; //输入识别码大于10时,ch[9]赋值10
}
rem = sum % 11; //取余
if (rem == ch[9])
printf("Right"); //输入识别码与实际识别码相同时输出Right
else { //输入识别码与实际识别码不同
for (int j = 0; j < 10; j++) { //依次输出ISBN码,若余数大于10输出X
if (ch[j] < 10) {
ch[9] = rem;
printf("%d", ch[j]);
} else printf("X");
if (j == 0 || j == 3 || j == 8) printf("-");
}
}
return 0;
}
int main() {
int ch[10], sum = 0, rem = 0;
for (int i = 0; i < 10; i++) {
scanf("%1d", &ch[i]);
if (ch[i] < 10) {
if (i == 0 || i == 3 || i == 8) scanf("-");
if (i != 9) sum += ch[i] * (i + 1); //计算数字和
}
if (ch[9] % 10 == 0) ch[9] = 10; //输入识别码大于10时,ch[9]赋值10
}
rem = sum % 11; //取余
if (rem == ch[9])
printf("Right"); //输入识别码与实际识别码相同时输出Right
else { //输入识别码与实际识别码不同
for (int j = 0; j < 10; j++) { //依次输出ISBN码,若余数大于10输出X
if (ch[j] < 10) {
ch[9] = rem;
printf("%d", ch[j]);
} else printf("X");
if (j == 0 || j == 3 || j == 8) printf("-");
}
}
return 0;
}