【十二题解】 | #计算日期到天数转换#

计算日期到天数转换

http://www.nowcoder.com/practice/769d45d455fe40b385ba32f97e7bcded

#include<stdio.h>

//公历年份是4的倍数,且不是100的倍数的

int main(){

int year, month, day;
while(scanf("%d", &year) != EOF){
    scanf("%d", &month);
    scanf("%d", &day);
    int all = 0;
    int run = 0;
    if(year%4==0 && year%100 != 0)run = 1;
    int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    for(int i=0; i<month-1; i++){
        all+=days[i];
    }
    all += day;
    if(month>2 && run)all+=1;
    printf("%d\n", all);
}

}

全部评论

相关推荐

喜欢喜欢喜欢:这是我见过最长最臭的简历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务