• 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
    ");
            else if(p1>0)
            {
                printf("The correct time is %d:%c%c
    ",h1,m11,m12);
            }
            else if(p2>0)
            {
                printf("The correct time is %d:%c%c
    ",h2,m21,m22);
            }
            else if(p3>0)
            {
                printf("The correct time is %d:%c%c
    ",h3,m31,m32);
            }
        }
        return 0;
    }
  • 相关阅读:
    由 基本数据型态转换成 String/ 由 String 转换成 数字的基本数据型态
    屏幕适配(UGUI)非UI
    转载 Unity Text 插入超链接
    File类的使用
    抽奖
    竖倾斜ScrollView
    本地资源_Asset
    小型自动朝向转盘
    简易C# socket
    Lua class
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/4728968.html
Copyright © 2020-2023  润新知