水题Q2005
来源:互联网 发布:淘宝网上眼镜店哪家好 编辑:程序博客网 时间:2024/05/22 13:20
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
1985/1/202006/3/12
Sample Output
2071
import java.util.Scanner;public class Q2005 {static int[] cy = {31,28,31,30,31,30,31,31,30,31,30,31};//平年static int[] ly = {31,29,31,30,31,30,31,31,30,31,30,31};//闰年public static void main(String[] args){Scanner s = new Scanner(System.in);while(s.hasNext()){String str = s.next();//输入字符串 如:1987/3/20int year = Integer.parseInt(str.substring(0, 4));int month ;int day ;int past = 0;//这一年已经过去的天数,即这一年的第几天if(str.charAt(6) == '/'){month = Integer.parseInt((str.substring(5,6)));day = Integer.parseInt(str.substring(7));}else {month = Integer.parseInt(str.substring(5,7));day = Integer.parseInt(str.substring(8));}if(!((year%4==0 && year%100!=0) || (year%400==0))){//如果不是闰年for(int i = 0 ; i < month-1 ; i ++){past += cy[i];}past += day;}else {for(int i = 0 ; i < month-1 ; i ++){past += ly[i];}past += day;}System.out.println(past);}s.close();}}
- 水题Q2005
- 水题
- 水题
- 水题
- 水题
- 【水题】
- 水题
- 水题:
- 水题
- 水题~
- 水题
- 水题
- 水题
- 水题
- 水题
- 水题
- 【水题】
- 水题
- VC++6.0中,返回值为一个结构体时,对象复制2次的问题
- 什么是IEEE 802.11
- Spring MVC 中的基于注解的 Controller
- mysql根据数据库自动生成实体(dto,service,impl,mybatis,xml)
- linux 连公司网络
- 水题Q2005
- 关于表单设计 每个管理执行人员都应该知道的
- How to Realize the Two's Complement of -128?
- 线性代数导论12——图和网络
- STL容器学习第一天
- maven中涉及到的编码格式
- 根据个人所得算缴税和税后收入
- Web前端黑客技术揭秘 笔记2
- 中国与印度软件开发之比较