zoukankan      html  css  js  c++  java
  • C语言拯救计划Day6-1之计算天数

    本题要求编写程序计算某年某月某日是该年中的第几天。

    输入格式:
    输入在一行中按照格式“yyyy/mm/dd”(即“年/月/日”)给出日期。注意:闰年的判别条件是该年年份能被4整除但不能被100整除、或者能被400整除。闰年的2月有29天。

    输出格式:
    在一行输出日期是该年中的第几天。

    输入样例1:
    2009/03/02

    输出样例1:
    61

    输入样例2:
    2000/03/02

    输出样例2:
    62

     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <stdlib.h>
     4 
     5 int isleap(int y){
     6     return y%4==0 && y%100!=0 || y%400==0;
     7 }
     8 int tab[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};
     9 int main()
    10 {
    11     int y,m,d,r=0;
    12     scanf("%d/%d/%d", &y,&m,&d);
    13     for(int i=1;i<m;i++){
    14         r+=tab[i];
    15         if(i==2 && isleap(y)) r+=1;
    16     }
    17     r+=d;
    18   printf("%d",r);
    19     return 0;
    20 }
  • 相关阅读:
    InitializingBean
    线程池
    maven
    mysql主从库
    zookeeper
    分布式服务框架 Zookeeper -- 管理分布式环境中的数据
    远程调试
    enum
    注解
    Shell错误[: missing `]'
  • 原文地址:https://www.cnblogs.com/noobchen/p/12836855.html
Copyright © 2011-2022 走看看