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
| #include<iostream> #include<string> #include<algorithm> using namespace std;
class SpString { friend SpString s_reverse(SpString t); friend ostream& operator<<(ostream& cout,SpString k); friend int Stoi(SpString t); public: void operator=(string t); void operator++(); bool operator<=(string t); SpString subs(int index,int len); private: string s; }; SpString SpString::subs(int index,int len) { SpString t; t=s.substr(index,len); return t; } int Stoi(SpString t) { return stoi(t.s); } void SpString::operator++() { for(int i=s.length()-1;i>=0;--i) { s[i]++; if(s[i]>'9'){ s[i]='0'; } else break; } } SpString s_reverse(SpString t) { reverse(t.s.begin(),t.s.end()); SpString k; k=t.s; return k; } void SpString::operator=(string t) { s=t; } ostream& operator<<(ostream& cout,SpString k) { cout<<k.s; return cout; } bool SpString::operator<=(string t) { return s<=t; } int isr(int year) { if(year%400==0||(year%100!=0&&year%4==0)) return 1; return 0; } int main() { int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int cnt=0,j; SpString s; for(s="0001",j=1;s<="2021";++s,++j) { int b=isr(j); month[2]=(b==1?29:28); SpString tmp=s_reverse(s); int t1=Stoi(tmp.subs(0,2)),t2=Stoi(tmp.subs(2,2)); if(t1<=12&&t1>0) { if(t2<=month[t1]&&t2>0) { cout<<++cnt<<" "<<s<<tmp<<endl; } } } return 0; }
|