#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;
}
#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;
}
本文介绍了一种通过输入小时、分钟和秒来计算时针与分针之间最小角度差的C语言程序实现方法。该程序考虑了不同时间情况下时针与分针之间的角度变化,并通过精确计算得出结果。
1665

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



