日期问题升级版

题目:输入 年 月 日 三个数字,按照年/月/日,月/日/年,日/月/年排序,并且检查其日期的合法性范围在1960.1.1到2059.12.31.

源代码:

#include<stdio.h>
#include<math.h>
int days1[14]={0,31,28,31,30,31,30,31,31,30,31,30,31};
int days2[14]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int data[10][4];
int i=0;
int leapdays(int year)
{
    if (year%4==0&&year%100!=0||year%400==0)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
void check (int y,int m,int d)
{
    if (y>=60)
    {
        y=19*100+y;
    }
    else
    {
        y=20*100+y;
    }
    if (m>12||m<=0)
    {
        return ;
    }
    if (leapdays(y))
    {
        if (days2[m]<d)
        {
            return ;
        }
    }
    else
    {
        if (days1[m]<d)
        {
            return ;
        }
    }
    data[i][0]=y;
    data[i][1]=m;
    data[i][2]=d;
    i++;
    
    
}
int main ()
{
    int a,b,c,d,e,f,g;
    scanf("%d%d%d",&a,&b,&c);
    check(a,b,c);
    check(c,a,b);
    check(c,b,a);
    for (int j=0;j<i;j++)
    {
        printf("%d/%02d/%02d\n",data[j][0],data[j][1],data[j][2]);
    }
    return 0;
}

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值