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
| #include <bits/stdc++.h>
using namespace std;
string c;
struct node{ string yy,mm,dd; }d[10];
bool cmd(const node& a, const node& b){ if(a.yy != b.yy) return a.yy < b.yy; else if(a.mm != b.mm) return a.mm < b.mm; else{ a.dd < b.dd; } }
int main(){ cin >> c; string yy,mm,dd; int cnt = 0; int day[12] = {31,28,31,30,31,30,31,31,30,31,30,31}; for(int i=0;i<3;i++){ string str = c; bool flag = false; if(i == 0){ yy = str.substr(0,2); mm = str.substr(3,2); dd = str.substr(6,2); } else if(i == 1){ yy = str.substr(6,2); mm = str.substr(0,2); dd = str.substr(3,2); } else{ yy = str.substr(6,2); mm = str.substr(3,2); dd = str.substr(0,2); } if(yy <= "59"){ yy = "20" + yy; } else{ yy = "19" + yy; } string t = yy; int a = stoi(t); if(mm <= "00" || mm > "12"){ continue; } else if(mm == "02"){ if(a % 400 == 0 || (a % 4 == 0 && a % 100 !=0 )){ if(dd > "29" || dd <= "00" ) continue; } else{ if(dd > "28" || dd <= "00" ) continue; } } else if(mm == "01" || mm == "03" || mm == "05" || mm == "07" || mm == "08" || mm == "10" || mm == "12"){ if(dd <= "00" || dd > "31"){ continue; } } else{ if(dd <= "00" || dd > "30"){ continue; } } for(int i=0;i<cnt;i++){ if(yy == d[i].yy && mm == d[i].mm && dd == d[i].dd) flag = true; } if(flag) continue; d[cnt] = {yy,mm,dd}; cnt ++; } sort(d,d+cnt,cmd); for(int i=0;i<cnt;i++){ cout << d[i].yy << "-" << d[i].mm << "-" << d[i].dd << "\n"; } return 0; }
|