/* Author: Anny Description: ¨­¤ÀÃÒÀˬd½X Date: 2006/12/04 Filename: idtest.c */ #include #include int main() { char a_id[10]; char c_id[11]; int check_num; int check; int i; gets(a_id); check_num = a_id[9] - '0'; switch (a_id[0]) { case 'A': c_id[0] = 1; c_id[1] = 0; break; case 'B': c_id[0] = 1; c_id[1] = 1; break; case 'C': c_id[0] = 1; c_id[1] = 2; break; case 'D': c_id[0] = 1; c_id[1] = 3; break; case 'E': c_id[0] = 1; c_id[1] = 4; break; case 'F': c_id[0] = 1; c_id[1] = 5; break; case 'G': c_id[0] = 1; c_id[1] = 6; break; case 'H': c_id[0] = 1; c_id[1] = 7; break; case 'I': c_id[0] = 3; c_id[1] = 4; break; case 'J': c_id[0] = 1; c_id[1] = 8; break; case 'K': c_id[0] = 1; c_id[1] = 9; break; case 'L': c_id[0] = 2; c_id[1] = 0; break; case 'M': c_id[0] = 2; c_id[1] = 1; break; case 'N': c_id[0] = 2; c_id[1] = 2; break; case 'O': c_id[0] = 3; c_id[1] = 5; break; case 'P': c_id[0] = 2; c_id[1] = 3; break; case 'Q': c_id[0] = 2; c_id[1] = 4; break; case 'R': c_id[0] = 2; c_id[1] = 5; break; case 'S': c_id[0] = 2; c_id[1] = 6; break; case 'T': c_id[0] = 2; c_id[1] = 7; break; case 'U': c_id[0] = 2; c_id[1] = 8; break; case 'V': c_id[0] = 2; c_id[1] = 9; break; case 'W': c_id[0] = 3; c_id[1] = 2; break; case 'X': c_id[0] = 3; c_id[1] = 0; break; case 'Y': c_id[0] = 3; c_id[1] = 1; break; case 'Z': c_id[0] = 3; c_id[1] = 3; break; } for (i=2; i<=9; i++) c_id[i] = a_id[i-1]-'0'; check = c_id[0] * 1; for (i=1; i<=9; i++) check += c_id[i] * (10-i); //printf("check = %d\n", check); check %= 10; if (check > 0) check = 10 - check; printf("check_num = %d\n\n", check_num); printf("check = %d\n", check); if (check_num == check) printf("Valid ID.\n"); else printf("Invalid ID.\n"); system("PAUSE"); return 0 ; }