POJ 2815 Context-Free Clock

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.

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

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).

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值