题解 | #[NOIP2008]ISBN号码#
[NOIP2008]ISBN号码
https://www.nowcoder.com/practice/95712f695f27434b9703394c98b78ee5
#include <stdio.h> void print(int sum,char* pc) { int i=0; for(i=0;i<9;i++) { if(i==1||i==4) printf("-"); printf("%c",pc[i]); } if(sum==10) printf("-X\n"); else printf("-%c",sum+'0'); } int main() { char arr[10] = { 0 }; int i = 0; for (i = 0; i < 10; i++) { if (i == 1 || i == 4 || i == 9) getchar(); scanf("%c", &arr[i]);//0-670-82162-4 } int sum = 0; for (i = 0; i < 9; i++) { sum += (arr[i] - '0') * (i + 1); } sum %= 11; if (sum == 10) { if (arr[9] == 'X') printf("Right\n"); else print(sum, arr); } else { if (arr[9] == (sum + '0')) printf("Right\n"); else print(sum, arr); } return 0; }