题目描述 写了140行的垃圾代码
我真的太笨了,第一时间想不到枚举所有的日期的方法。
于是用模拟写法写了。
总结: 菜和笨
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int m[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
bool judge(int year)
{
if(year%400==0|| (year%4==0&&year%100!=0) ) return true;
else return false;
}
struct date
{
int year;
int month;
int day;
}d[10];
bool cmp(date a,date 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 main(void)
{
int x1,x2,x3;
scanf("%d/%d/%d",&x1,&x2,&x3);
int sum=x1+1900;//x1为年 x2为月 x3为日
int number=0;
if(sum>=1960&&sum<=2059)
{
if(judge(sum))
m[2]=29;
if(x2>=1&&x2<=12)
{
if(x3>=1&&x3<=m[x2])
{
d[number].year=sum;
d[number].month=x2;
d[number++].day=x3;
}
}
m[2]=28;
}
sum=x1+2000;
if(sum>=1960&&sum<=2059)
{
if(judge(sum))
m[2]=29;
if(x2>=1&&x2<=12)
{
if(x3>=1&&x3<=m[x2])
{
d[number].year=sum;
d[number].month=x2;
d[number++].day=x3;
}
}
m[2]=28;
}
int sum2=x3+1900;//x1为月 x2为日 x3为年
if(sum2>=1960&&sum2<=2059)
{
if(judge(sum2))
m[2]=29;
if(x1>=1&&x1<=12)
{
if(x2>=1&&x2<=m[x1])
{
d[number].year=sum2;
d[number].month=x1;
d[number++].day=x2;
}
}
m[2]=28;
}
sum2=x3+2000;
if(sum2>=1960&&sum2<=2059)
{
if(judge(sum2))
m[2]=29;
if(x1>=1&&x1<=12)
{
if(x2>=1&&x2<=m[x1])
{
d[number].year=sum2;
d[number].month=x1;
d[number++].day=x2;
}
}
m[2]=28;
}
int sum3=x3+1900;//x1为日 x2为月 x3为年
if(sum3>=1960&&sum3<=2059)
{
if(judge(sum3))
m[2]=29;
if(x2>=1&&x2<=12)
{
if(x1>=1&&x1<=m[x2])
{
d[number].year=sum3;
d[number].month=x2;
d[number++].day=x1;
}
}
m[2]=28;
}
sum3=x3+2000;
if(sum3>=1960&&sum3<=2059)
{
if(judge(sum3))
m[2]=29;
if(x2>=1&&x2<=12)
{
if(x1>=1&&x1<=m[x2])
{
d[number].year=sum3;
d[number].month=x2;
d[number++].day=x1;
}
}
m[2]=28;
}
sort(d,d+number,cmp);
printf("%d-%02d-%02d\n",d[0].year,d[0].month,d[0].day);
for(int i=1;i<number;i++)
{
//去重
if( (d[i].year==d[i-1].year) && (d[i].month==d[i-1].month) && (d[i].day==d[i-1].day) )
continue;
printf("%d-%02d-%02d\n",d[i].year,d[i].month,d[i].day);
}
return 0;
}