Dowemo
0 0 0 0

Question number: 201509 -2

Question name: date calculation

Time limit: 1.0 s

Memory limit: 256.0 mb

Problem description:
Given a year y and an integer d, ask the year for the year to be a few months.
Note 2 months for leap leap months. To meet one of the following conditio & is a leap year:
1 ) the year is a single number of 4, and isn't an integer of 100;
2 ) the year is an integer of 400.

Enter format
The fi & t line entered contai & an integer y that represents the year, between 1900 to 2015 ( with 1900 and 2015 ).
The second line entered contains an integer d, d between 1 to 365.

Output format
Output two lines, one per line, representing the month and date of the answer.

Sample input
2015
80

Sample output
3
21

Sample input
2000
40

Sample output
2
9

import java.util.Scanner;publicclassT201509_2 {staticint y;
 staticint d;
 staticint m = 1; //从1月开始publicstaticvoidmain(String[] args) {
 Scanner sc = new Scanner(System.in);
 y = sc.nextInt();
 d = sc.nextInt();
 sc.close();
 boolean rn = false; //闰年if((y%4==0 && y%100!=0) || y%400==0) //是否闰年 rn = true;
 while(d> 0){
 switch (m) {
 //31天的月份case1:case3:case5:case7:case8:case10:case12:
 cal(31);
 break;
 //30天的月份case4:case6:case9:case11:
 cal(30);
 break;
 //2月case2:
 if(rn) cal(29);
 else cal(28);
 break;
 }
 }
 }
 /**
 * 计算
 * @param day 每一月的天数
 */staticvoid cal(int day){
 if(d> day){ //剩余d超过一个月 d -= day;
 m++; //月份计数 }else{ //剩余d就在本月 System.out.println(m); //月 System.out.println(d); //日 d = 0; //退出主函数中的while循环 }
 }
}

这里写图片描述




Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs