Clock

Given a time HH:MM:SS and one parameter   a a, you need to calculate next time satisfying following conditions:  

1. The angle formed by the hour hand and the minute hand is   a a.  
2. The time may not be a integer(e.g. 12:34:56.78), rounded down(the previous example 12:34:56).  

Input
The input contains multiple test cases.  

Each test case contains two lines.  
The first line is the time HH:MM:SS (0HH<12,0MM<60,0SS<60) (0≤HH<12,0≤MM<60,0≤SS<60).  
The second line contains one integer   a(0a180) a(0≤a≤180).  
Output
For each test case, output a single line contains test case number and the answer HH:MM:SS.  
Sample Input
0:59:59
30
01:00:00
30
Sample Output

Case #1: 01:00:00Case #2: 01:10:54

题意:给一个当前时间和一个角度,要求输出时针和分针成当前角度的一个最近时刻

首先我们推算出,秒针每走1°,分针走1/10°,时针走1/120°,所以干脆全部乘120,得到120->12->1,因此我们把120当作1°,所以只要将360*120当作秒针走一周的度数就可以处理,这样处理的优点是排除误差

接下来就可以暴力求解出几秒后可以得到解,因为我们对度数处理过,所以每过1s,时针度数+1,分针度数+12,判断一下当前锁形成的角度即可

代码如下

#include<stdio.h>
#include<iostream>
#include<math.h>
using namespace std;
int abs(int a)
{
    if(a<0)
        return -a;
        else
            return a;
}
int main()
{
    int a,b,c;
    int g=0;
    while(scanf("%d:%d:%d",&a,&b,&c)!=-1)
    {
        ++g;
        int we;
        scanf("%d",&we);
        we=we*120;
        int sum=a*3600+b*60+c;
        int hh=sum%(360*120);
        int mm=(sum*12)%(360*120);
        int ans=0;
        while(1)
        {
            ans++;
            hh=(hh+1)%(360*120);
            mm=(mm+12)%(360*120);
            if(abs(abs(hh-mm)-we)<=10) break;
        }
        printf("Case #%d: ",g);
       int ansc=(ans+c)%60;
       int ansm=(b+(ans+c)/60)%60;
       int ansh=(a+((((ans+c)/60)+b)/60))%12;
        printf("%02d:%02d:%02d\n",ansh,ansm,ansc);
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值