C++ 代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int mouth_sz[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool _year(int y){
if(y<1960 || y>2059) return false;
if(y%400==0 || y%4==0 && y%100!=0){
mouth_sz[2]=29;
}
else mouth_sz[2]=28;
return true;
}
bool _mouth(int mouth){
if(mouth>0 && mouth <= 12){
return true;
}
return false;
}
bool _day(int mouth,int day){
if(day>0 && day<=mouth_sz[mouth]) return true;
else return false;
}
bool work(int data){
int year=data/10000;
int mouth=data/100%100;
int day=data%100;
if(!_year(year)) return false;
if(!_mouth(mouth)) return false;
if(!_day(mouth,day)) return false;
return true;
}
int main(){
int a,b,c,temp;
scanf("%d/%d/%d",&a,&b,&c);
int n[6]={(2000+a)*10000+b*100+c,(2000+c)*10000+a*100+b,(2000+c)*10000+b*100+a,
(1900+a)*10000+b*100+c,(1900+c)*10000+a*100+b,(1900+c)*10000+b*100+a};
for(int i=0;i<3;i++){//从小到大排序
for(int j=0;j<3;j++){
if(n[i]<n[j]){
temp=n[i];
n[i]=n[j];
n[j]=temp;
}
}
}
int panchong[6];
bool t=true;
for(int i=0,j;i<6;i++){
t=true;
if(work(n[i])){
for(j=0;j<6;j++){
if(n[i]==panchong[j]) t=false;
}
if(!t) continue;
panchong[i]=n[i];
printf("%02d-%02d-%02d\n",n[i]/10000,n[i]/100%100,n[i]%100);
}
}
return 0;
}