Guest User

Untitled

a guest
Mar 21st, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int englishCalculate(char);
  4. int numberCalculate(char,int);
  5.  
  6. int main() {
  7. char idCard[10];
  8. int total;
  9.  
  10. cout << "請輸入欲被檢查之身分證\n";
  11. cin >> idCard;
  12.  
  13. total = englishCalculate(idCard[0]);
  14. for (int x = 1; x < 10; x++) {
  15. total += numberCalculate(idCard[x] - 48,x);
  16. }
  17. if (total % 10 == 0) {
  18. cout << "正確!!";
  19. } else {
  20. cout << "錯誤!!";
  21. }
  22.  
  23. return 0;
  24. }
  25.  
  26. int englishCalculate(char idCard) {
  27. int x;
  28. switch(idCard) {
  29. case 'A':
  30. case 'B':
  31. case 'C':
  32. case 'D':
  33. case 'E':
  34. case 'F':
  35. case 'G':
  36. case 'H':
  37. x = 55;
  38. break;
  39. case 'I':
  40. x = 39;
  41. break;
  42. case 'J':
  43. case 'K':
  44. case 'L':
  45. case 'M':
  46. case 'N':
  47. x = 56;
  48. break;
  49. case 'O':
  50. x = 35;
  51. break;
  52. case 'P':
  53. case 'Q':
  54. case 'R':
  55. case 'S':
  56. case 'T':
  57. case 'U':
  58. case 'V':
  59. x = 57;
  60. break;
  61. case 'W':
  62. x = 55;
  63. break;
  64. case 'X':
  65. case 'Y':
  66. x = 58;
  67. break;
  68. case 'Z':
  69. x = 57;
  70. break;
  71. default:
  72. cout << "錯誤!!";
  73. }
  74.  
  75. return (idCard - x) / 10 + ((idCard - x) % 10) * 9;
  76. }
  77.  
  78. int numberCalculate(char idCard,int x) {
  79. int y;
  80. if (x == 9) {
  81. y = 1;
  82. } else {
  83. y = 9 - x;
  84. }
  85. return idCard * y;
  86. }
Add Comment
Please, Sign In to add comment