杭电2005(第几天?)java字符串水过
2015-04-16 17:51
429 查看
点击打开杭电2005
1、split的应用:将字符串以某某字符为界划分为多个字符串
2、面向对象的编程
Problem Description
给定一个日期,输出这个日期是该年的第几天。
Input
输入数据有多组,每组占一行,数据格式为YYYY/MM/DD组成,具体参见sample input ,另外,可以向你确保所有的输入数据是合法的。
Output
对于每组输入数据,输出一行,表示该日期是该年的第几天。
Sample Input
Sample Output
1、split的应用:将字符串以某某字符为界划分为多个字符串
2、面向对象的编程
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 MyDate{ int year ,month,day; int[] months={0,31,0,31,30,31,30,31,31,30,31,30}; public MyDate(String str){ this.set(str); } public void set(String str){ String[] s=str.split("/"); this.year=Integer.parseInt(s[0]); this.month=Integer.parseInt(s[1]); this.day=Integer.parseInt(s[2]); } public boolean isLeapYear(){ return year%400==0||year%4==0&&year%100!=0; } public int daysOfYear(){ if(isLeapYear()){ this.months[2]=29; }else{ this.months[2]=28; } int sum=0; for(int i=1;i<this.month;i++){ sum+=months[i]; } return sum+this.day; } } class Main{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); while(sc.hasNext()){ String str=sc.next(); MyDate d=new MyDate(str); System.out.println(d.daysOfYear()); } } }
相关文章推荐
- 杭电 2005 ( 第几天? ) java
- 杭电oj(Java版)——2005 第几天?
- 杭电2005 第几天?
- hdoj 2005(java) 第几天?
- 杭电ACM--2005第几天
- 杭电 2005 第几天?
- 杭电ACM 2005 第几天?
- 第几天?(杭电2005)
- 【杭电2005】第几天?
- 杭电2005题(求一年的第几天)
- 杭电 2005 第几天?
- hdu 2005 第几天? java版
- 杭电 2005 第几天?
- 【杭电】[2005]第几天?
- 杭电2005 第几天
- 杭电OJ 2005.第几天?
- 杭电ACM2005题(第几天?)------Java语言
- 【杭电-oj】-2005-第几天?
- 【杭电】2005 第几天?
- 杭电2005 第几天 函数形式