zoukankan      html  css  js  c++  java
  • (HDOJ 2005)第几天?

    第几天?
    Problem Description
    给定一个日期,输出这个日期是该年的第几天。
     

    Input
    输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
     

    Output
    对于每组输入数据,输出一行,表示该日期是该年的第几天。
     

    Sample Input
    1985/1/20 
    2006/3/12
     

    Sample Output
    20 
    71
     

     AC code:

    #include<stdio.h>
    #include
    <math.h>

    int isleapyear(int y)
    {
         
    if(((y%4==0&& (y%100!=0))||(y%400==0))
         {
           
    return 1;
         }
         
    else
         {
           
    return 0;
         }
    }

    int main()
    {
         
    int year,month,day;
         
    char l,m;
         
    int y[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}};
      
    while(scanf("%d%c%d%c%d",&year,&l,&month,&m,&day)!=EOF)
      {
           
    int i,j,n=0;
           i
    =isleapyear(year);
           
    for(j=0; j<month-1;j++)
           {
             n
    += y[i][j];
           }
           n
    +=day;
           printf(
    "%d\n",n);
           n
    =0;
         }
         
    return 0;

    } 

    作者:cpoint
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
  • 相关阅读:
    oracle使用expdp备份数据库
    用Setuptools构建和分发程序包
    C#5.0-原生异步编程方式
    任务并行库
    线程-线程池1
    多线程-3(同步)
    多线程-2(线程同步)
    线程---1
    高性能-GC3
    高性能-GC2
  • 原文地址:https://www.cnblogs.com/cpoint/p/2015345.html
Copyright © 2011-2022 走看看