题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
https://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
#include <stdio.h> //当想将字符数字被用做整型数字时,定义一个新的整型变量,该整型变量的大小=字符-48 int main() { int a, b, c, d; char arr; scanf("%d-%d-%d-%c", &a, &b, &c, &arr); d = (arr == 'X'? 10 : arr - 48);//将数字字符转换成对应的整型数字 int sum = a * 100000000 + b * 100000 + c; int end = 0; int i = 0; for (i = 9; i > 0; i--) { int y = 0; y = sum % 10; sum /= 10; end += y * i; } //判断 if (end % 11 == d) { printf("Right\n"); } else { if (end % 11 == 10) { printf("%d-%d-%d-X\n", a, b, c); } else { printf("%d-%d-%d-%d\n", a, b, c, end % 11); } } return 0; } //如果觉得代码对您有帮助的话,您的点赞是对我莫大的鼓舞,谢谢!