/**
枚举可能的情况然后进行检验,并去重,使用set集合去重
如果set容器里用自己定义的类或者是结构体类型的,不要忘记重载<符号。
并且 set的iterator类型自动就是const的引用类型, 因此当set保存的是类类型时,对iterator解引用
无法调用类的菲const成员,所以要在韩束的后面加上const
*/
#include<iostream>
#include<set>
#include<iterator>
using namespace std;
int md[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
void myInsert(int year,int month,int day);
struct Date{
int year;
int month;
int day;
Date (int y,int m,int d)
{
year = y;
month = m;
day = d;
}
bool is_ok()
{
if(year<1960||year>2059) return false;
if(month<1||month>12) return false;
if((year%4==0&&year%100!=0)||year%400==0) //闰年
{
if(month==2)
{
return day>0&&day<=29;
}
else return day>0&&day<=md[month];
}
else return day>0&&day<=md[month];
}
//重载<符号
bool operator < (Date b) const
{
if(year == b.year)
{
if(month == b.month)
{
return day<b.day;
}
return month<b.month;
}
return year<b.year;
}
void print() const
{
cout<<year<<"-";
if(month<10) cout<<"0";
cout<<month<<"-";
if(day<10) cout<<"0";
cout<<day<<endl;
}
};
set<Date> ss;
void myInsert(int year,int month,int day)
{
Date d(year,month,day);
if(d.is_ok())
ss.insert(d);
}
int main()
{
int a,b,c;
char fu;
cin>>a>>fu>>b>>fu>>c;
//年月日
myInsert (a+1900,b,c);
myInsert (a+2000,b,c);
//月日年
myInsert(1900+c, a, b);
myInsert(2000+c, a, b);
//日月年
myInsert(1900+c, b, a);
myInsert(2000+c, b, a);
set<Date>::iterator it = ss.begin();
for(;it!=ss.end();it++)
{
it->print();
}
return 0;
}