zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    .net操作oracle,一定要用管理员身份运行 visual studio 啊,切记切记,免得报奇怪的错误。
    基于 bootstrap 的 vue 分页组件
    前端UI框架《Angulr》入门
    EF 中 Code First 的数据迁移以及创建视图
    Oracle自动备份.bat 最新更新(支持Win10了)
    总结一下Android中主题(Theme)的正确玩法
    并不优雅
    思考:有三扇门,其中一扇门里有奖品,三选一,你选择其中一扇门之后,主持人先不揭晓答案,而是从另外两扇门中排除掉一个没有奖品的门,现在主持人问你,要不要换个门,请问你换还是不换?
    TensorFlow开发者证书 中文手册
    在C#下使用TensorFlow.NET训练自己的数据集
  • 原文地址:https://www.cnblogs.com/13224ACMer/p/4728968.html
Copyright © 2011-2022 走看看