函式_身分證驗證
user_3763047219
c_cpp
2 years ago
810 B
5
Indexable
void ID_Check(char ID[]); #include <stdio.h> #include <stdlib.h> void ID_Check(char ID[]) { int n1 = ID[0]; if (n1== 73) { n1 = 34; } else if (n1 == 81) { n1 = 35; } else if (n1 < 73){ n1 = n1 - 55; } else if (n1 < 81) { n1 = n1 - 56; } else if (n1 > 81) { n1 = n1 - 57; } ID[0] = ' '; int IDnum =atoi(ID); int sum = (n1 / 10) + (n1 % 10) * 9 +IDnum%10; for (int i = 0; i <= 8; i++) { sum = sum + IDnum % 10 * i; IDnum = IDnum / 10; } if (sum % 10 == 0) { printf("real"); } else { printf("fake"); } } int main() { char ID[100]; while (scanf("%s", ID) != EOF) { ID_Check(ID); } return 0; }
Editor is loading...