HDU 4177 模拟时间问题

Avoiding a disaster

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 211    Accepted Submission(s): 101


Problem Description
Percy likes to be punctual. So much so that he always keeps three watches with him, so that he can be sure exactly what the time is. However, Percy's having a bad day. He found out that one of his watches was giving the wrong time. What's worse, when he went to correct the watch, he corrected the wrong one! That is, one watch was running x minutes behind (where x <= 480) and he wound one of the other watches x minutes forward. He now has three watches reading three different times, and hence is in serious danger of being tardy. Can you help Percy by writing a program that takes in the three times displayed on the watches and returns the correct time?
 

 

Input
The input begins with an integer T indicating the number of cases that follow (0 < T
< 100). Each of the following T lines contains one test case, made up of three readings, separated by single space characters: H1:M1 H2:M2 H3:M3 In each reading H1,H2,H3 represent the hours displayed (0 < H1,H2,H3 < 13), and M1,M2,M3 represent the minutes displayed (0 <= M1,M2,M3 < 60).
If the number of minutes is less than 10, a leading 0 is added.
 

 

Output
For each test case, one line should be produced, formatted exactly as follows: "The
correct time is Hi:Mi". If the number of minutes is less than 10, a leading 0 should be
added. If the number of hours is less than 10, a leading 0 should NOT be added. If it is impossible to tell the time from the three readings, print the string: "Look at the sun".
 

 

Sample Input
3 5:00 12:00 10:00 11:59 12:30 1:01 12:00 4:00 8:00
 

 

Sample Output
The correct time is 5:00 The correct time is 12:30 Look at the sun
 

 

Source
 

 

Recommend
lcy   |   We have carefully selected several similar problems for you:   4178  4186  4180  4181  4182 
 
 
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        char c1,c2,c3;
        int h1,h2,h3;
        char m11,m12,m21,m22,m31,m32;
        scanf("%d%c%c%c",&h1,&c1,&m11,&m12);
        getchar();
        scanf("%d%c%c%c",&h2,&c2,&m21,&m22);
        getchar();
        scanf("%d%c%c%c",&h3,&c3,&m31,&m32);
        int min1=0,min2=0,min3=0;
        min1=h1*60+m11*10+m12;
        min2=h2*60+m21*10+m22;
        min3=h3*60+m31*10+m32;
        int p1=0,p2=0,p3=0;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min1+=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min1-=12*60;
        min2+=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min2-=12*60;
        min3+=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min1+=12*60;
        min2+=12*60;
        min3-=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min2-=12*60;
        min3+=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min1-=12*60;
        min2+=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        min1+=12*60;
        if(min1+min2==2*min3&&fabs(min1-min3)<=480)
            p3++;
        else if(min1+min3==2*min2&&fabs(min1-min2)<=480)
            p2++;
        else if(min3+min2==2*min1&&fabs(min3-min1)<=480)
            p1++;
        if(p1>0&&p2>0||p1>0&&p3>0||p2>0&&p3>0)
            printf("Look at the sun\n");
        else if(p1>0)
        {
            printf("The correct time is %d:%c%c\n",h1,m11,m12);
        }
        else if(p2>0)
        {
            printf("The correct time is %d:%c%c\n",h2,m21,m22);
        }
        else if(p3>0)
        {
            printf("The correct time is %d:%c%c\n",h3,m31,m32);
        }
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/13224ACMer/p/4728968.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值