C++代码
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <sstream>
using namespace std;
int x, y, z;
string s;
int date[3];
int cnt[100000000];
bool judge_date(int year, int month, int day)
{
int k[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if(month < 1 || month > 12) return false;
if(day < 1 || day > k[month]) return false;
if(!((year % 100 != 0 && year % 4 == 0) || year % 400 == 0) && month == 2)
if(day > 28) return false;
return true;
}
int main()
{
int year, month, day;
scanf("%d/%d/%d", &x, &y, &z);
if(x >= 60 && x <= 99) date[0] = 19*1000000 + x * 10000 + y * 100 + z;
else date[0] = 20*1000000 + x * 10000 + y * 100 + z;
if(z >= 60 && z <= 99) date[1] = 19*1000000 + z * 10000 + x * 100 + y;
else date[1] = 20*1000000 + z * 10000 + x * 100 + y;
if(z >= 60 && z <= 99) date[2] = 19*1000000 + z * 10000 + y * 100 + x;
else date[2] = 20*1000000 + z * 10000 + y * 100 + x;
sort(date, date + 3);
for(int i = 0; i < 3; i ++)
{
if(cnt[date[i]] == 0){
year = date[i] / 10000;
month = (date[i] / 100) % 100;
day = date[i] % 100;
if(judge_date(year, month, day))
printf("%04d-%02d-%02d\n", year, month, day);
}
cnt[date[i]] ++;
}
return 0;
}
//枚举三种可能的排列,并从小到大排列,依次判断是否符合日期的条件