zoukankan      html  css  js  c++  java
  • 练习2 D 题- 第几天?

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
     

    Description

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

    Input

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

    Output

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

    Sample Input

    1985/1/20
    2006/3/12
     

    Sample Output

    20
    71
     
    #include<stdio.h>
    int main()
    {
        int year,month,day,i;
        while(scanf("%d/%d/%d",&year,&month,&day)!=EOF) 
          { 
             i=0;
             switch(month-1)
              {
                case 11: i+=30;
                case 10: i+=31;
                case 9:  i+=30;
                 case 8:  i+=31;
                case 7:  i+=31;
                case 6:  i+=30;
                case 5:  i+=31;
                case 4:  i+=30;
                case 3:  i+=31;
                case 2:  if((year%4==0&&year%100!=0)||(year%400==0))
                         i+=29;
                         else
                         i+=28;
                case 1:  i+=31;
              }
            i+=day;
            printf("%d
    ",i);
         }
         return 0;
    }
  • 相关阅读:
    使用lambda的精简写法
    lambda实现集合遍历 排序
    stream流 list转map
    stream.min
    lambda实现线程调用
    stream.allMatch
    stream.reduce
    stream流 of
    Stream流 list转set
    SQL Server 游标的简单介绍 转载
  • 原文地址:https://www.cnblogs.com/hfc-xx/p/4903696.html
Copyright © 2011-2022 走看看