首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >HDOJ 2005 第几天?

HDOJ 2005 第几天?

作者头像
谙忆
发布于 2021-01-19 15:14:55
发布于 2021-01-19 15:14:55
6510
举报
文章被收录于专栏:程序编程之旅程序编程之旅

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

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

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

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

Sample Output 20 71

代码语言:javascript
复制
import java.util.*;
class Main{
   public static void main(String args[]){
      Scanner sc = new Scanner(System.in);
      while(sc.hasNext()){
          String str = sc.next();
                String strs[]=str.split("/");
                int year = Integer.parseInt(strs[0]);
                int month = Integer.parseInt(strs[1]);
                int day = Integer.parseInt(strs[2]);
         int s=0,run_1=0;
         if(run(year)){
            run_1=1;
         }
         switch(month){
               case 12: s+=30;           
               case 11: s+=31;
               case 10: s+=30;
               case 9 : s+=31;
               case 8 : s+=31;
               case 7 : s+=30;
               case 6 : s+=31;
               case 5 : s+=30;
               case 4 : s+=31;
               case 3 : s+=28+run_1;
               case 2 : s+=31;
            }
         s+=day;
         System.out.println(s);
      }
   }
   public static boolean run(int year){
      if((year%100!=0&&year%4==0)||(year%400==0))
         return true;
      return false;
   }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015/10/22 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档