-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBirthNumbersValidator.cpp
More file actions
75 lines (60 loc) · 1.42 KB
/
BirthNumbersValidator.cpp
File metadata and controls
75 lines (60 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <utility>
#include <set>
#include <cctype>
using namespace std;
class BirthNumbersValidator {
public:
int toInt(string s) {int r = 0; istringstream ss(s); ss >> r; return r;}
long long toLong(string s) {long long r = 0; istringstream ss(s); ss >> r; return r;}
vector <string> validate(vector <string> test)
{
vector <string> ret;
int d[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
vector <int> days(d, d+12);
for (int i=0; i<test.size(); i++)
{
long long all = toLong(test[i]);
int year = toInt(test[i].substr(0, 2));
int month = toInt(test[i].substr(2, 2));
int day = toInt(test[i].substr(4, 2));
if (year >= 7)
year += 1900;
else
year += 2000;
if (!((0 < month && month < 13) || (50 < month && month < 63)))
{
ret.push_back("NO");
continue;
}
if (month > 50)
month -= 50;
int limit = days[month-1];
if (month == 2 && (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)))
limit++;
if (!(0 < day && day <= limit))
{
ret.push_back("NO");
continue;
}
if (all % 11 != 0)
{
ret.push_back("NO");
continue;
}
ret.push_back("YES");
}
return ret;
}
};
// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor