Context-Free Clock
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 984 | Accepted: 379 |
Description
You recently installed a stylish clock in your office that is perfectly round and has no markings that identify its orientation. After accidentally bumping it, you realized that 12 o'clock might no longer be at the top. Nonetheless, you want to figure out what time it is. Fortunately you recently overheard A a coworker giving the time and you have a protractor and can measure the angle between the hour and minute hands.
Your program should print the first time that has the correct angle between the hour and minute hands and that is on or after the overheard time. The angle (0 to 359 degrees, inclusive) will be measured clockwise from the hour hand to the minute hand. Assume that the clock hands move smoothly.
Your program should print the first time that has the correct angle between the hour and minute hands and that is on or after the overheard time. The angle (0 to 359 degrees, inclusive) will be measured clockwise from the hour hand to the minute hand. Assume that the clock hands move smoothly.
Input
Input will consist of one test case per line, of the form
A HH :MM :SS
where A is the integral number of degrees that must be traversed clockwise to get from the hour hand to the minute hand and HH : MM : SS is the overheard time in 24 hour form. 0 <= A <= 359 , 0 <= HH <= 23 , 0 <= MM <= 59 , and 0 <= SS <= 59 . HH , MM , and SS will be exactly two digits with a leading zero if necessary.
End of input will be signaled by the line
-1 00:00:00
A HH :MM :SS
where A is the integral number of degrees that must be traversed clockwise to get from the hour hand to the minute hand and HH : MM : SS is the overheard time in 24 hour form. 0 <= A <= 359 , 0 <= HH <= 23 , 0 <= MM <= 59 , and 0 <= SS <= 59 . HH , MM , and SS will be exactly two digits with a leading zero if necessary.
End of input will be signaled by the line
-1 00:00:00
Output
Output will consist of one line per test case, of the form
HH :MM :SS
where HH : MM : SS is the first time on or after the input time where the angle from the hour hand to the minute hand is exactly A degrees, rounded down to the nearest second. HH, MM , and SS should be zero padded to two digits and in the same range as the input ( 0...23 , 0...59 , and 0...59 respectively).
HH :MM :SS
where HH : MM : SS is the first time on or after the input time where the angle from the hour hand to the minute hand is exactly A degrees, rounded down to the nearest second. HH, MM , and SS should be zero padded to two digits and in the same range as the input ( 0...23 , 0...59 , and 0...59 respectively).
Sample Input
270 14:45:00 0 12:00:00 0 12:00:01 300 13:30:00 180 08:30:00 -1 00:00:00
Sample Output
15:00:00 12:00:00 13:05:27 14:00:00 09:16:21
package poj; import java.util.Scanner; public class Poj2815_20120815_0 { // 1s: s:6 m:1/10 h:1/120 public static void main(String[] args) { Scanner in = new Scanner(System.in); int a; double s,m,h, ts, nt,ns; String str; String [] time; while(true){ a = in.nextInt(); str = in.next(); if(a == -1 && "00:00:00".equals(str)){ break; } time = str.split(":"); h = Double.parseDouble(time[0]); m = Double.parseDouble(time[1]); s = Double.parseDouble(time[2]); // h %= 24; ts = h*3600+m*60+s; //当前已走过的总秒数。 nt = (ts * 11.0/120)% 360; //当前相差分针时针相差度数。 if(a<nt){ //如果当前相差度数大于了目标要求度数。则多走 360 度。 a += 360; } ns = 120 * (a-nt)/11.0; ts += ns; h = (ts/3600.0) % 24; ts %= 3600; m = (ts/60.0)%60; ts %= 60; s = ts; System.out.printf("%02d:%02d:%02d ",(int)h,(int)m,(int)s); System.out.println(); } } }