0
点赞
收藏
分享

微信扫一扫

HDOJ 2005 第几天?


Problem Description

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

Input

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

Output

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

Sample Input

1985/1/20

2006/3/12

Sample Output

20

71

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;
}
}



举报

相关推荐

6001 第几天?

第几天,明码

c语言:第几天

求第几天C

Java习题练习:第几天

zzulioj1129: 第几天

0 条评论