#include <stdio.h> int Search_yushu(int a, int b, int c) { int sum = a; int i = 4; while (b) { int y = b % 10; sum += y * i--; b /= 10; } i = 9; while (c) { int y = c % 10; sum += y * i--; c /= 10; } return sum % 11; } int main() { int a, b, c; char d; scanf("%d-%d-%d-%c", &a, &b, &c, &d); int e = Search_yushu(a, b, c); if(e == 10) { e = 'X'; if(e != d) printf("%d-%d-%d-%c", a, b, c, e); else printf("Right"); } else if (e == d - 48) printf("Right"); else printf("%d-%d-%d-%d", a, b, c, e); return 0; }
开始觉得挺简单,其实它真的挺难。难点有3:第一在于末尾,我可以输入数字0到9,也可以输入X,这样就只能用char类型变量来进行输入了,那么字符数字变成纯数字怎么弄?简单来说就是-48或者说-'0'。第二在于余数怎么求。最后这道题对条件的梳理要求较高,各个分支要明白代表什么。