时间复杂度
不高
C++ 代码
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int months[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int check(int y) {
if ((y % 100 != 0 && y % 4 == 0) || y % 400 == 0)return 1;
else return 0;
}
struct node {
int a=0;
int b=0;
int c=0;
int k=0;
}day[5];
int cou = 0;
bool cmp(node a, node b) {
return a.k < b.k;
}
void res(int a, int b, int c) {
cou++;
if (a >= 0 && a <= 59) {
a = 2000 + a;
}
else if (a == 60)a = 1960;
else a = 1900 + a;
if (b >= 1 && b <= 12);
else return ;
if (b != 2) {
if (c >= 1 && c <= months[b]);
else return ;
}
if (b==2) {
if(check(a))
if (c > 29)return;
if(!check(a))
if (c > 28)return ;
}
day[cou].a = a;
day[cou].b = b;
day[cou].c = c;
day[cou].k = a * 1000 + b * 100 + c;
}
int main()
{
int a, b, c;
char z, x;
cin >> a >> z >> b >> x >> c;
res(a, b, c);
res(c, a, b);
res(c, b, a);
sort(day + 1, day + 4, cmp);
for (int i = 1; i <= 3; i++) {
if (day[i].k != day[i - 1].k) {
cout << day[i].a << "-";
if (day[i].b < 10)cout << "0" << day[i].b << "-";
else cout << day[i].b << "-";
if (day[i].c < 10)
cout << "0" << day[i].c << endl;
else cout << day[i].c<< endl;
}
}
return 0;
}
大佬牛逼