Description
Input
Output
Sample Input
4 00:00:00 06:00:00 12:54:55 04:40:00
Sample Output
0 0 0 180 180 0 1391/24 1379/24 1/2 100 140 120
题意: 给你一个24格式的数字时间,(字符串),问你这个时刻时针与分针 时针与秒针 分针与秒针 之间的夹角,
挺简单的水题,我们发现 秒针每秒转6度,分针每秒转1/10度,每分转6度,时针每小时转30度,没分转1/2度,没秒转
1/120 度,那么我们将表盘看做一个坐标系,12点钟为起点,那么可以计算出每个指针这一刻的角度是多少,但是为了避免
分数的加减,我们将所有的数通分,同时乘以120,那么圆盘一圈360 度变成了360*120 =43200度,肯定在int内,将时间转化
为12制的时间,计算角度,然后做差得到角度,但是输出是范围是0-180 ,所以要求小角,选择 min(x,43200-x)作为差值
,然后要化简为最简分式就可以了,(分子是120)
看代码
#include
#include
#include
#include
#include
using namespace std;
int gcd(int a,int b)
{
if(b==0)
return a;
else
return gcd(b,a%b);
}
int main()
{
int h,m,s;
int H,M,S;
int ans1,ans2,ans3;
char str[20];
int t;
cin>>t;
while(t--)
{
cin>>str;
h=(str[0]-'0')*10+(str[1]-'0');
m=(str[3]-'0')*10+(str[4]-'0');
s=(str[6]-'0')*10+(str[7]-'0');
if(h>=12)
h-=12;
//cout<