蓝桥杯日期问题,测试点1,2过不了
https://www.lanqiao.cn/problems/103/learning/?page=1&first_category_id=1&sort=students_count&name=%E6%97%A5%E6%9C%9F%E9%97%AE%E9%A2%98
#include<iostream>
using namespace std;
int year(int yea)//判断闰年
{
if(yea/400==0)
return 1;
if(yea/4==0&&yea/100!=0)
return 1;
else
return 0;
}
int mouth(int mou,int yea)//判断月份
{
int flag=0,day=0;
flag=year(yea);
if(flag==1)
day=29;
else
day=28;
switch(mou)//可用月份数组代替
{
case 1:flag= 31;break;
case 3:flag= 31;break;
case 5:flag=31;break;
case 7:flag= 31;break;
case 8:flag= 31;break;
case 10:flag= 31;break;
case 12:flag= 31;break;
case 2:flag= day;break;
case 4:flag= 30;break;
case 6:flag= 30;break;
case 9:flag= 30;break;
case 11:flag= 30;break;
}
return flag;
}
int main()
{
int year[3]={0},mouthn[3]={0},day[3]={0};
int a=0,b=0,c=0;
int h=0;
scanf("%02d/%02d/%02d",&a,&b,&c);
if(a>=0&&a<=99)//年/月/日
{
if(b>=1&&b<=12)
{
int data=mouth(b,a);
if(c<=data&&c>=1)
{
year[0]=a;
mouthn[0]=b;
day[0]=c;
}
}
}
if(a>=1&&a<=12)//月/日/年
{
int data=mouth(a,c);
if(b<=data&&b>=1)
{
if(c>=0&&c<=99)
{
year[1]=c;
mouthn[1]=a;
day[1]=b;
}
}
}
int data=mouth(b,c);
if(a<=data&&a>=1)//日/月/年
{
if(b>=1&&b<=12)
{
if(c>=0&&c<=99)
{
year[2]=c;
mouthn[2]=b;
day[2]=a;
}
}
}
if(year[0]==year[1]&&mouthn[0]==mouthn[1]&&day[0]==day[1])
{
year[0]=0;
}
if(year[0]==year[2]&&mouthn[0]==mouthn[2]&&day[0]==day[2])
{
year[0]=0;
}
if(year[1]==year[2]&&mouthn[1]==mouthn[2]&&day[1]==day[2])
{
year[1]=0;
}
int sum[3]={0};
int min=0;
int min_num=0;
int x,y,z;
for(int k=0;k<3;k++)
{
x=year[k];
y=mouthn[k];
z=day[k];
sum[k]=(x-1960)*365+y*30+z;
}
for( h=0;h<3;h++)
{
min=60000;
for(int k=0;k<3;k++)
{
if(sum[k]<min&&sum[k]!=0)
{
min=sum[k];
min_num=k;
}
}
sum[min_num]=60000;
if(year[min_num]!=0)
{
if(year[min_num]<=59)
printf("20%02d-%02d-%02d\n",year[min_num],mouthn[min_num],day[min_num]);
else
printf("19%02d-%02d-%02d\n",year[min_num],mouthn[min_num],day[min_num]);
}
}
return 0;
}