题目链接:
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=170523
题意:
问从这个整点出发,之前或之后时针与分针成一个角度的时刻。
思路:
模拟题。错误点是之前情况的时间的转换,其中最难发现的地方是时针处什么时候-mi%60,什么时候-mi/60-1。应该是se%3600 == 0而不是mi%60 == 0;
源码:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main()
{
// freopen("data.txt","r",stdin);
// freopen("data1.txt","w",stdout);
int t;scanf("%d",&t);
for(int i = 1; i<= t; i++){
int a,b;
char ss[20];
scanf("%d%s%d",&a,ss,&b);
int flag = ss[0]=='a'?1:0;
// printf("flag = %d\n",flag);
int len;
int pre = a;
int now = (12-b)*30;
if(flag){
if(pre < now)
len = 360+pre-now;
else
len = pre-now;
}
else{
if(pre <= now)
len = now - pre;
else
len = 360 - pre + now;
}
if(len == 0)
len = 360;
double ti = 120.0 * len / 11;
// printf("len = %d,ti = %f\n",len,ti);
int se = ti;
if(ti- se >= 0.5)
se++;
int mi,ho;
if(flag){
// if(ti - se >= 0.5)
// se++;
mi = se / 60;
ho = mi / 60 + b;
mi %= 60;
se %= 60;
}
else{
// if(ti - se < 0.5)
// se++;
// printf("use time is se = %d,mi= %d,ho = %d\n",se,se/60,se/3600);
mi = se / 60;
// printf("first mi =%d\n",mi);
if(se % 3600 == 0)
ho = b - mi / 60;
else
ho = b - mi / 60 - 1;
if(se % 60 == 0)
mi = (60 - mi%60)%60;
else
mi = (59 - mi%60);
// printf("for mi =%d\n",mi);
se = (60 - se%60)%60;
}
if(ho > 12)
ho -= 12;
if(ho < 1)
ho += 12;
printf("Case %d: %d:%02d:%02d\n",i,ho,mi,se);
}
return 0;
}
//19 : 34 : 15 + 0 : 25 : 45 = 20 : 00 : 00
// 25 * 60 + 45 = 1500 + 45 = 1545
//19 : 35 : 00 + 0 : 25 : 00 = 20 : 00 : 00
// 25 * 60 = 1500