思路

可恶啊,这道题居然交了12遍 + 看题解 + AIdebug才过

看到题解里很多dalao,居然还有枚举1960-2059年每个月每一天的,就为了找是否满足条件()

我一开始的思路交上去时全红

之后想想要判断闰年 + 不超过12个月 + 不超过每个月天数吧,交上去是3个点绿,其余红

看了眼题解恍然大悟,原来要去重 + 从小到大排序
交上去是88分,wa了一个点

这时候就要靠AI了,代码喂给gpt之后恍然大悟,哦哦,原来月份不止要不超过12月,还要不小于1月,日期同理不小于1

交上去也是ac了

难度:中位橙,读题要仔细

代码

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
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

bool isrun(int x){
if (x % 400 == 0)
return true;
if (x % 100 != 0 && x % 4 == 0)
return true;
return false;
}

bool isok(string t){
int md[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int y = 0, m = 0, d = 0;
for (int i = 0; i < 4; i++)
{
y = y * 10 + t[i] - '0';
}
m = (t[5] - '0') * 10 + t[6] - '0';
d = (t[8] - '0') * 10 + t[9] - '0';
if (isrun(y)){
md[2] = 29;
}
if (y < 1960 || y > 2059)
return false;
if (m < 1 || m > 12){
return false;
}
if (d < 1 || d > md[m]){
return false;
}
return true;
}

bool cmp(const string &p, const string &q){
int py = 0, pm = 0, pd = 0;
for (int i = 0; i < 4; i++)
{
py = py * 10 + p[i] - '0';
}
pm = (p[5] - '0') * 10 + p[6] - '0';
pd = (p[8] - '0') * 10 + p[9] - '0';
int qy = 0, qm = 0, qd = 0;
for (int i = 0; i < 4; i++)
{
qy = qy * 10 + q[i] - '0';
}
qm = (q[5] - '0') * 10 + q[6] - '0';
qd = (q[8] - '0') * 10 + q[9] - '0';
if (py == qy)
{
if (pm == qm)
{
return pd < qd;
}
return pm < qm;
}
return py < qy;
}

signed main(){
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
string s;
cin >> s;
string re = "";
vector<pair<string, int>> a;
int y1 = (s[0] - '0') * 10 + (s[1] - '0');
int y2 = (s[3] - '0') * 10 + (s[4] - '0');
int y3 = (s[6] - '0') * 10 + (s[7] - '0');
string s1 = "";
s1 = s1 + s[0] + s[1];
string s2 = "";
s2 = s2 + s[3] + s[4];
string s3 = "";
s3 = s3 + s[6] + s[7];
a.push_back(make_pair(s1, y1));
a.push_back(make_pair(s2, y2));
a.push_back(make_pair(s3, y3));

unordered_set<string> b;
string t1 = (a[0].second <= 59 ? "20" : "19") + a[0].first + '-' + a[1].first + '-' + a[2].first;
string t2 = (a[2].second <= 59 ? "20" : "19") + a[2].first + '-' + a[0].first + '-' + a[1].first;
string t3 = (a[2].second <= 59 ? "20" : "19") + a[2].first + '-' + a[1].first + '-' + a[0].first;
for(string ss : {t1,t2,t3}){
if(isok(ss)){
b.insert(ss);
}
}
vector<string> c(b.begin(),b.end());
sort(c.begin(), c.end(), cmp);
for (int i = 0; i < c.size(); i++)
{
cout << c[i] << endl;
}
return 0;
}