陈老师的多校联合20140818||Uvalive 5683 模拟

https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3684

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$ \le$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 H1H2H3 represent the hours displayed ( 0 < H1, H2, H3 < 13), and M1M2,M3 represent the minutes displayed ( 0$ \le$M1, M2, M3 < 60).

If the number of minutes is less than 10, a leading 0 is perpended.

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
解题思路:x最大不过8小时,我们吧时间调到一个24小时内找三者中间点,若相差不是4小时即可。
 
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int judge[8],sum[8],h[4],m[4],a[4];

int ab(int x)
{
    if(x<0)
        return -x;
    return x;
}
int ji_suan(int x,int y,int z,int &k)
{
    if(ab(x-y)==ab(y-z))
    {
        k = y;
        return ab(x-y);
    }
    else if(ab(x-z)==ab(y-z))
    {
        k = z;
        return ab(x-z);
    }
    else if(ab(x-y)==ab(z-x))
    {
        k = x;
        return ab(x-y);
    }
    else
    {
        k = -1 ;
        return -1;
    }
}

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int a[4];
        for(int i=1; i<=3; i++)
            scanf("%d:%d",&h[i],&m[i]);
        for(int i=1; i<=3; i++)
            a[i] = h[i]*60+m[i];
        int flag = 0;
        //24小时内换算
        judge[1] = ji_suan(a[1],a[2],a[3],sum[1]);
        judge[2] = ji_suan(a[1]+720,a[2],a[3],sum[2]);
        judge[3] = ji_suan(a[1],a[2]+720,a[3],sum[3]);
        judge[4] = ji_suan(a[1],a[2],a[3]+720,sum[4]);
        judge[5] = ji_suan(a[1]-720,a[2],a[3],sum[5]);
        judge[6] = ji_suan(a[1],a[2]-720,a[3],sum[6]);
        judge[7] = ji_suan(a[1],a[2],a[3]-720,sum[7]);
        for(int i=1; i<8; i++)
            if(judge[i]>0)
            {
                flag = 1;
                if(judge[i] == 240)//正好是一个环
                {
                    printf("Look at the sun\n");
                    break;
                }
                else
                {
                    printf("The correct time is %d:%02d\n",sum[i]/60,sum[i]%60);
                    break;
                }
            }
        if(!flag)
            printf("Look at the sun\n");
    }
    return 0;
}
/**

99
5:00 12:00 10:00
11:59 12:30 1:01
12:00 4:00 8:00
1:01 2:01 3:01

**/


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值