题目:http://ac.jobdu.com/problem.php?pid=1553
/*
分别算出时针和分针的度数,做差之后分几种情况讨论,(-360,-180),[-180,0),[0,180],(180,360).
*/
#include <stdio.h>
int main(){
int h,m;
while (~scanf("%d:%d",&h,&m)) {
double hd,md,mdd;
hd = (h%12)*30;
md = m*6;
mdd = ((double)m)/2;
double temp = hd + mdd - md;
//printf("%.2lf %.2lf %.2lf %.2lf\n",hd,md,mdd,temp);
if(temp > 180)
printf("%.2lf\n",360 - temp);
else if (temp < 0 && (temp > -180 || temp == -180) )
printf("%.2lf\n",-temp);
else if(temp < -180)
printf("%.2lf\n",360 + temp);
else
printf("%.2lf\n",temp);
}
return 0;
}
本文提供了一种解决时钟上时针与分针夹角问题的方法,通过计算时针和分针各自的角度并进行比较,针对不同情况讨论了如何得到最短夹角。

887

被折叠的 条评论
为什么被折叠?



