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了,坑

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

代码如下:

 # include <iostream>
# include<cstdio>
# include<cstring>
using namespace std; int main()
{
int a,b,c,d,ans;
double tmp1,tmp2,tmp3,tmp4;
printf("Program 3 by team X\n");
printf("Initial time Final time Passes\n");
while(scanf("%d%d%d%d",&a,&b,&c,&d)!= EOF)
{
printf(" ");
printf("%02d:%02d",a,b);
printf(" ");
printf("%02d:%02d",c,d);
printf(" ");
if(a==)
a=;
if(c==)
c=;
tmp2 = b/60.0;
tmp1 = a/12.0 + tmp2/12.0;
tmp4 = d/60.0;
tmp3 = c/12.0 + tmp4/12.0;
if(a==c)
{
if(d>=b)
{
if(tmp1-tmp2> && tmp4-tmp3>)
{
ans = ;
}
else
ans = ;
}
else
{
ans = ;
if(tmp1 - tmp2 > )
ans++;
if(tmp4-tmp3>)
ans ++;
}
}
else if(a<c)
{
ans = c-a-;
if(tmp1 - tmp2 > )
ans++;
if(tmp4 - tmp3 > )
ans++;
}
else
{
ans = -a + c -;
if(tmp1 - tmp2 > )
ans++;
if(tmp4 - tmp3>)
ans++;
}
printf("%2d\n",ans);
}
printf("End of program 3 by team X\n");
return ;
}
05-02 02:45