0%

回文日期

今天 20211202

回文日期标准:

​ 年份取四位,月、日取二位

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;
}

结果:

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
1 01011010
2 01100110
3 01111110
4 01200210
5 01211210
6 01300310
7 01400410
8 01500510
9 01600610
10 01700710
11 01800810
12 01900910
13 02011020
14 02100120
15 02111120
16 02200220
17 02211220
18 02300320
19 02400420
20 02500520
21 02600620
22 02700720
23 02800820
24 02900920
25 03011030
26 03100130
27 03111130
28 03211230
29 03300330
30 03400430
31 03500530
32 03600630
33 03700730
34 03800830
35 03900930
36 10011001
37 10100101
38 10111101
39 10200201
40 10211201
41 10300301
42 10400401
43 10500501
44 10600601
45 10700701
46 10800801
47 10900901
48 11011011
49 11100111
50 11111111
51 11200211
52 11211211
53 11300311
54 11400411
55 11500511
56 11600611
57 11700711
58 11800811
59 11900911
60 12011021
61 12100121
62 12111121
63 12200221
64 12211221
65 12300321
66 12400421
67 12500521
68 12600621
69 12700721
70 12800821
71 12900921
72 13011031
73 13100131
74 13211231
75 13300331
76 13500531
77 13700731
78 13800831
79 20011002
80 20100102
81 20111102
82 20200202
83 20211202