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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| #include<iostream> #include<string>
using namespace std;
class Date { protected: int year, month, day; public: Date(int y,int m,int d):year(y), month(m), day(d){}
bool check() { int monthDay[] = { 31,isLeap() ? 29 : 28,31,30,31,30,31,31,30,31,30,31 }; if (day < 0 || year < 0 || month < 0 || year > 2015 || month > 12 || day > monthDay[month - 1]) return false; return true; }
bool isLeap() { return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0); }
int getY(){ return year;} int getM(){ return month;} int getD(){ return day;}
void print() { printf("%d年%d月%d日", year, month, day); } };
class OldID { protected: string id15, name; Date birthday; public: OldID(string id, string na, int y, int m, int d):id15(id), name(na), birthday(y, m, d){}
bool check() { if(id15.size() != 15) return false;
for(char i : id15) if(i < '0' || i > '9') return false;
if(!birthday.check()) return false;
string d; for(int i = 6, j = 0; j < 6; i ++ , j ++ ) d += id15[i]; int a = stoi(d); int b = birthday.getY() % 100 * 10000; b += birthday.getM() * 100 + birthday.getD(); if(a != b) return false;
return true; }
void print() { cout << name << endl; } };
class NewID:public OldID { private: string id18; Date issueday; int validay; public: NewID(string name, int y1, int m1, int d1,string id1, string id2, int y2, int m2, int d2, int v):OldID(id1,name,y1,m1,d1), id18(id2),issueday(y2,m2,d2),validay(v){}
bool check() { int a[17]={7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2}; int sum = 0, mod; for(int j = 0; j < 17; j ++ ) sum += (id18[j] - '0') * a[j]; mod = sum % 11; char ch[] = {'1','0','X','9','8','7','6','5','4','3','2'}; if(id18[17] != ch[mod]) return false;
int red, idd; string d; red = birthday.getY() * 10000 + birthday.getM() * 100 + birthday.getD(); for(int i = 6, j = 0; j < 8; i ++ , j ++ ) d += id18[i]; idd = stoi(d); if(idd != red) return false;
if(!issueday.check()) return false; if(birthday.getY() + validay < issueday.getY()) return false; for(int j = 0; j < 6; j ++ ) if(id15[j] != id18[j]) return false; for(int i = 14, j = 12; i < 17; i ++ , j ++ ) if(id15[j] != id18[i]) return false;
return true; }
void print() { cout << id18 << " "; issueday.print(); if(validay != 100) cout << " " << validay << "年" << endl; else cout << " 长期" << endl; } };
int main() { int t; cin >> t; string name, id15, id18; int y1,m1,d1,y2,m2,d2,v; for(int i = 0; i < t; i ++ ) { cin >> name >> y1 >> m1 >> d1 >> id15 >> id18 >> y2 >> m2 >> d2 >> v; NewID nid(name, y1, m1, d1, id15, id18, y2, m2, d2, v); nid.OldID::print(); if(nid.OldID::check() && nid.check()) nid.print(); else cout << "illegal id" << endl; } return 0; }
|