ZOJ 1122 Clock(模拟)

Clock

Time Limit: 2 Seconds      Memory Limit: 65536 KB

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

题目的下边还有一大段,当时出在HUST上,根本分不清哪输出格式是哪个,谁知道最前边最后边那句话也需要。当时有一次试了一下加上这两句,其他地方哪里又出错了。看了题解,直接把最后一次提交的错误代码, 加上这两句输出,直接A了,坑

判断分针和时针相遇的次数

代码如下:

 1 # include <iostream>
 2 # include<cstdio>
 3 # include<cstring>
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     int a,b,c,d,ans;
 9     double tmp1,tmp2,tmp3,tmp4;
10     printf("Program 3 by team X
");
11     printf("Initial time  Final time  Passes
");
12     while(scanf("%d%d%d%d",&a,&b,&c,&d)!= EOF)
13     {
14         printf("       ");
15         printf("%02d:%02d",a,b);
16         printf("       ");
17         printf("%02d:%02d",c,d);
18         printf("      ");
19         if(a==12)
20             a=0;
21         if(c==12)
22             c=0;
23         tmp2 = b/60.0;
24         tmp1 = a/12.0 + tmp2/12.0;
25         tmp4 = d/60.0;
26         tmp3 = c/12.0 + tmp4/12.0;
27                if(a==c)
28         {
29             if(d>=b)
30             {
31                 if(tmp1-tmp2>0 && tmp4-tmp3>0)
32                 {
33                     ans = 1;
34                 }
35                 else
36                     ans = 0;
37             }
38             else
39             {
40                 ans = 10;
41                 if(tmp1 - tmp2 > 0 )
42                     ans++;
43                 if(tmp4-tmp3>0)
44                     ans ++;
45             }
46         }
47         else if(a<c)
48         {
49             ans = c-a-1;
50             if(tmp1 - tmp2 > 0 )
51                 ans++;
52             if(tmp4 - tmp3 > 0)
53                 ans++;
54         }
55         else
56         {
57             ans = 11-a + c -1;
58             if(tmp1 - tmp2 >0 )
59                 ans++;
60             if(tmp4 - tmp3>0)
61                 ans++;
62         }
63         printf("%2d
",ans);
64     }
65     printf("End of program 3 by team X
");
66     return 0;
67 }
原文地址:https://www.cnblogs.com/acm-bingzi/p/3597569.html