注意去重
代码如下:
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
struct node
{
int year,month,day;
}book[3];
int cmp(node a,node b)
{
if(a.year==b.year)
{
if(a.month==b.month)
{
return a.day>b.day;
}
return a.month>b.month;
}
return a.year>b.year;
}
int Day[2][13]={0,31,28,31,30,31,30,31,31,30,31,30,31,
0,31,29,31,30,31,30,31,31,30,31,30,31};
int vis[2100][13][32];
int pan(int year) //闰年
{
if(year%4==0 && year%100!=0 || year%400==0)
return 1;
return 0;
}
int dayjudge(int day,int k,int month) //天数合法
{
if(Day[k][month]<day || day<1)
return 0;
return 1;
}
int monthjudge(int month) //月份合法
{
if(month<1 || month>12)
return 0;
return 1;
}
int sj(int year) //年份
{
if(year>=60 && year<=99)
return year+1900;
return year+2000;
}
int adc(const char a[]) //转换
{
int data=(a[0]-'0')*10+(a[1]-'0');
return data;
}
int main()
{
int i,j,cnt=0;
char s[10],data[3][3];
cin>>s;
memset(vis,0,sizeof(vis));
for(i=0;i<3;i++)
{
for(j=0;j<2;j++)
data[i][j]=s[cnt++];
data[i][j]=0;
cnt++;
}
int year,month,day,t;
for(i=cnt=0;i<3;i++)
{
if(i==0)
{
year=adc(data[0]);
year=sj(year);
month=adc(data[1]);
day=adc(data[2]);
t=pan(year); //平年或闰年
if(!monthjudge(month))
continue;
if(!dayjudge(day,t,month))
continue;
book[cnt].year=year;
book[cnt].month=month;
book[cnt].day=day;
vis[year][month][day]=1;
cnt++;
}
else if(i==2)
{
year=adc(data[2]);
year=sj(year);
month=adc(data[0]);
day=adc(data[1]);
t=pan(year); //平年或闰年
if(!monthjudge(month))
continue;
if(!dayjudge(day,t,month))
continue;
book[cnt].year=year;
book[cnt].month=month;
book[cnt].day=day;
if(vis[year][month][day])
continue;
vis[year][month][day]=1;
cnt++;
}
else
{
year=adc(data[2]);
year=sj(year);
month=adc(data[1]);
day=adc(data[0]);
t=pan(year); //平年或闰年
if(!monthjudge(month))
continue;
if(!dayjudge(day,t,month))
continue;
book[cnt].year=year;
book[cnt].month=month;
book[cnt].day=day;
if(vis[year][month][day])
continue;
vis[year][month][day]=1;
cnt++;
}
}
sort(book,book+cnt,cmp);
while(cnt)
{
printf("%d-%02d-%02d\n",book[cnt-1].year,book[cnt-1].month,book[cnt-1].day);
cnt--;
}
return 0;
}