Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ConsoleApplication2.cpp : 定義主控台應用程式的進入點。
- //
- #include "stdafx.h"
- #include <iostream>
- #include <string>
- #include <cctype>
- using namespace std;
- void main()
- {
- string s, num = "0123456789";
- bool check = true;
- cout << "nplease input ID:";
- while (getline(cin, s))
- {
- if (s.size() != 10)
- {
- cout << "ID應為10碼\n";
- check = false;
- }
- if (isalpha(s[0]))
- {
- if (s.find_first_not_of(num,1) != string::npos)
- {
- cout << "後九碼應為數字\n";
- check = false;
- }
- }
- else
- {
- cout << "第一碼應為英文字母\n";
- check = false;
- }
- if (check)
- {
- cout << "is ID\n";
- }
- else
- {
- cout << "not ID\nplease input ID:";
- continue;
- }
- int letter_number[] = { 10, 11, 12, 13, 14, 15, 16, 17, 34, 18, 19, 20, 21, 22, 35, 23, 24, 25, 26, 27, 28, 29, 32, 30, 31, 33 };
- if (islower(s[0]))
- {
- s[0] = toupper(s[0]);
- }
- int sum = letter_number[(s[0] - 'A')] / 10 + letter_number[(s[0] - 'A')] % 10 * 9;
- for (int i = 1; i < 9; i++)
- {
- sum += (s[i] - '0')*(9 - i);
- }
- int checknum = (10 - (sum % 10)) % 10;
- if (checknum == (s[9] - '0'))
- {
- cout << "true ID\n";
- }
- else
- {
- cout << "fake ID\n";
- }
- cout << "please input ID:";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement