zoukankan      html  css  js  c++  java
  • HDU_2005——今天是今年的第几天

    Problem Description
    给定一个日期,输出这个日期是该年的第几天。
     
    Input
    输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
     
    Output
    对于每组输入数据,输出一行,表示该日期是该年的第几天。
     
    Sample Input
    1985/1/20 2006/3/12
     
    Sample Output
    20 71
     1 #include <cstdio>
     2 #include <cctype>
     3 const int days[12]={31,28,31,30,31,30,31,31,30,31,30,31};
     4 bool is_leapyear(int year)
     5 {
     6    if((year%4==0 && year%10!=0)||year%400==0)
     7       return true;
     8    return false;   
     9 }
    10 int main()
    11 {
    12    char str[15];
    13    while(~scanf("%s",str))
    14       {
    15          int a[3]={0},day=0;
    16          for(int i=0,j=0;str[i];i++)
    17             {
    18                if(isdigit(str[i]))
    19                   a[j]=a[j]*10+str[i]-'0';
    20                else
    21                   j++;     
    22             }
    23          for(int i=0;i<a[1]-1;i++)
    24             day=day+days[i];
    25          day=day+a[2];
    26          printf("%d\n",is_leapyear(a[0])?day+1:day);    
    27       }
    28    return 0;
    29 }
    ——现在的努力是为了小时候吹过的牛B!!
  • 相关阅读:
    Node.js Net 模块+DNS 模块
    php程序报500错误
    Node.js 工具模块-OS模块+path模块
    Node.js GET/POST请求
    Canvas动画+canvas离屏技术
    Python OS 模块
    Python random 模块
    Python time 模块
    Python 迭代器
    Python 生成器
  • 原文地址:https://www.cnblogs.com/pingge/p/3138061.html
Copyright © 2011-2022 走看看