您的位置:首页 > 编程语言 > C语言/C++

hdoj 2076 时针分针夹角C语言实现

2016-03-03 16:09 351 查看
#include <stdio.h>

#include <stdlib.h>

#include <math.h>

int main()

{

int h,m,s,n,i;

scanf("%d",&n);

for (i=0;i<n;i++)

{

scanf("%d %d %d",&h,&m,&s);

double x,y,degree;

x = (1.0/120)*(m*60+s);

y = 0.1*((m%5)*60+s);

if (h>12)

h = h - 12;

m = m/5;

if (h==m)

degree = abs(x-y);

if (h<m)

degree = (m-h)*30-x+y;

if (h>m)

degree = (h-m)*30-y+x;

if (degree>180.00)

degree = 360 - degree;

printf("%d\n",(int)degree); //注意不能使用%.0lf因为那样会自动四舍五入,所以用强制类型转换

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: