C++ 代码
#include<iostream>
#include<algorithm>
using namespace std;
const int N1=10000,N2=100;
bool is(int y,int m,int d){ //判断年月日是否为合法日期
int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(y>2059 || y<1960 ||m>12 ||d>31 ||m==0 ||d==0)return false;
if(y%400==0 || y%4==0&&y%100!=0)a[2]=29;
if(d>a[m])return false;
return true;
}
int main(){
int a,b,c;
int d[6]={0}; //可能的日期最多只有6个
scanf("%d/%d/%d",&a,&b,&c);
if(is(a+1900,b,c)) d[0]= (a+1900)*N1 + b*N2 + c; //将日期转为数字方便排序
if(is(a+2000,b,c)) d[1]= (a+2000)*N1 + b*N2 + c;
if(is(c+1900,a,b)) d[2]= (c+1900)*N1 + a*N2 + b;
if(is(c+2000,a,b)) d[3]= (c+2000)*N1 + a*N2 + b;
if(is(c+1900,b,a)) d[4]= (c+1900)*N1 + b*N2 + a;
if(is(c+2000,b,a)) d[5]= (c+2000)*N1 + b*N2 + a;
sort(d,d+6);
if( d[0] ) printf("%d-%02d-%02d\n",d[0]/N1, d[0]%N1/N2, d[0]%N1%N2); //若第一个非0则输出
for(int i=1; i<6; i++){ //输出无重复日期
if(d[i]&&d[i]!=d[i-1]) printf("%d-%02d-%02d\n",d[i]/N1, d[i]%N1/N2, d[i]%N1%N2);
}
return 0;
}