题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
https://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
#include <stdio.h> int main() { //录入字符串 char ch[20] = { 0 }; char* pc = ch; scanf("%s", pc); //计算九位数字与(1,2,3,...,9)乘积的和 //i是为了让数字往后推 int i = 0; int sum = 0; //而j就是1,2,....,9 //每计算一次就++ int j = 1; for (i = 0; i < 11; i++) { if (*(pc + i) != '-') { //数字字符 - '0' <==> 整型的值 sum += (*(pc + i) - '0') * j; j++; } } //计算最后的标识码的整型数值 int n = sum % 11; //用m来代替最后的识别码 char m = 0; if (n >= 0 && n <= 9) { m = n + '0'; } else { m = 'X'; } if (m + 0 == *(pc + 12) + 0) { printf("Right\n"); } else { *(pc + 12) = m; printf("%s", pc); } return 0; }