这道简单的题目为什么还要写解题报告呢?就是因为自己经常犯一个小错误,就是1.0*s/60这样的老是写成了0.1了,这样以后找错比较麻烦,所以还是吧代码贴了下来
哈哈
思路: 以12点为参考系,计算到12点的夹角
代码如下:
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int t, h, m, s;
double degree, hdegree, mdegree;
cin>>t;
while (t--)
{
cin>>h>>m>>s;
if (h>12)
{
h=h-12;
}
hdegree = 30.0*h+(1.0*m/60.0+1.0*s/3600.0)*30.0;//例如时从12到13的时候是30度,所以乘以30。。一个小时
mdegree = 6.0*m+1.0*s/60.0*6.0; //例如分从12也就是0到13(5)的时候是30度。。5分钟。。所以乘以6
degree = fabs(hdegree-mdegree);
if (degree > 180.0)
{
degree = 360.0-degree;
}
cout<<(int)degree<<endl;
}
return 0;
}