ZOJ_1122

ZOJ_1122: Clock

Time Limit: 2000 MS   Memory Limit: 64 MB   64bit IO Format: %lld

[ Submit][ Status][ Web Board]

Description

You are given a standard 12-hour clock with analog display, an hour hand and a minute hand. How many times does the minute hand pass the hour hand in a given time interval?

Sample Input 

12 50  1  2
 3  8  3 20
 2 45 11  0
11  0  3 20
 1  2 12 50
 3 20  3  8

Sample Output

Program 3 by team X
Initial time  Final time  Passes
       12:50       01:02       0
       03:08       03:20       1
       02:45       11:00       8
       11:00       03:20       4
       01:02       12:50      11
       03:20       03:08      10
End of program 3 by team X

The input contains an indefinite number of lines; each line contains four 
  numbers.
  
  The first pair of numbers represents an "initial time" the second 
  pair represents a "final time."
  
  In each such number pair, the first number represents hours, second number represents 
  minutes.
  
  The hours will be in the range 1..12, the minutes in the range 0..59.
  
  No initial time and no final time will be an instant at which the minute hand 
  just passes the hour hand. (In particular, 12 00 will not occur as an initial 
  or final time.)
  
  No initial time will be the same as the corresponding final time.
  
  Between each initial time and corresponding final time, the hour hand will have 
  turned less than one full revolution (360 degrees).
  
  As the hour hand turns from its initial position to its final position, it may 
  or may not sweep past the number 12 on the clock's dial.
  
  If it does, then either the initial time is an "A.M." time and the 
  final time a "P.M." time, or vice versa.
  
  If it does not, then either both times (initial and final) are "A.M." 
  or both are "P.M."
  
  Each line of input gives rise to one line of output, containing
  
  the initial and final times, and
  
  the number of times the minute hand passes the hour hand between the initial 
  time and the final time.
  
  Observe all details of formatting, such as upper/lower case letters, punctuation, 
  blank spaces, and the absence of blank lines.
  
  In each time display, the hours and minutes are displayed in fields of width 
  2, separated by a colon.
  
  The ten's digit (of hours or minutes) is displayed as a zero if it is zero.
  
  Here is a formatting template shown between two lines of the above output:

Initial time  Final time  Passes
12345678901234567890123456789012
       12:50       01:02       0

Source

Rocky Mountain 2000



题目很罗嗦,其实就是算一段时间内时针分针的相交次数。

需要知道12小时,时针与分针相交11次。

那么均匀分配到每一分钟,从0:0开始到s分钟以后,相交次数是 s*11/(60*12);

以及,输入的时间改成12小时制。

#include<cstdio>
#include<cstring>
#include<iostream>


using namespace std;




int main()
{
    int s1,e1,s2,e2;
    puts("Program 3 by team X");
    puts("Initial time  Final time  Passes");
    while(scanf("%d%d%d%d",&s1,&s2,&e1,&e2)!=EOF)
    {
        int m1,m2;
        m1=(s1%12*60+s2);
        m2=(e1%12*60+e2);


        int ans=m2*11/(60*12)-m1*11/(60*12);
        if(m1>m2)
            ans+=11;
        printf("       %02d:%02d       %02d:%02d%8d\n",s1,s2,e1,e2,ans);






    }
    puts("End of program 3 by team X");


    return 0;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值