stronger


私信TA

用户名:stronger

访问量:16624

签 名:

等  级
排  名 1852
经  验 2459
参赛次数 1
文章发表 22
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

有些时候,解决日期类要先看看是否要预处理。
参考代码:

#include <stdio.h>

#include <stdlib.h>

#define IS_LEAPYEAR(x) (x%4==0&&x%100!=0 || x%400==0 ? 1:0 )

struct data{

    int year;

    int month;

    int day;

};

int main()

{

    int ans=0,i,n;

    struct data temp;

    int dayofmonth[2][12]={31,28,31,30,31,30,31,31,30,31,30,31,

                           31,29,31,30,31,30,31,31,30,31,30,31};

    scanf("%d%d%d",&temp.year,&temp.month,&temp.day) ;

    n=temp.month-1;

    for(i=0;i<n;i++){

        ans+=dayofmonth[IS_LEAPYEAR(temp.year)][i];

    }

    printf("%d",temp.day+ans);

    return 0;

}


 

0.0分

0 人评分

  评论区