题目链接:UVa 579 - ClockHands
简单几何题。
注意变量不能命名为clock,貌似与UVa某些头文件冲突,与我自己的codeblocks没冲突。
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <iomanip>
using namespace std;
char _clock[10];
double m,res,h,m_a,h_a;
int main()
{
while(cin>>_clock,strcmp(_clock,"0:00"))
{
res = 0.0;
h = atof(_clock);
if(h >= 10)
m = atof(_clock + 3);
else
m = atof(_clock + 2);
m_a = m * 6.0;
h_a = h * 30.0 + m * 0.5;
if(m_a > h_a)
m_a = 360.0 - m_a;
else
h_a = 360.0 - h_a;
res = m_a + h_a;
if(res > 180)
res = 360.0 - res;
cout<<fixed<<setprecision(3)<<res<<endl;
}
return 0;
}