HDU 1209(Clock)

Basic problem, first calculates the minimum angle of each time the hour and minute hands, and in accordance with small to large angle, if the angle is the same, the earlier the top surface.

When structural input and output, scanf and printf convenient than cin and cout.

#include <cstdio>
#include <algorithm>
using namespace std;

struct Clock //钟表
{
	int h; //时
	int m; //分
	double angle; //角度
}c[5];

//排序标准
bool cmp(Clock c1, Clock c2)
{
	if (c1.angle != c2.angle)
		return c1.angle < c2.angle;
	else
		return (c1.h * 60 + c1.m) < (c2.h * 60 + c2.m);
}

int main()
{
	int T;
	scanf("%d", &T);
	while (T--)
	{
		int hour, minute; //时针数字,分针数字
		double angleH, angleM; //时针角度,分针角度
		for (int i = 0; i < 5; i++)
		{
			scanf("%d:%d", &hour, &minute);
			angleH = (hour % 12) * 30 + minute * 0.5;
			angleM = minute * 6;
			c[i].h = hour;
			c[i].m = minute;
			c[i].angle = min(max(angleH, angleM) - min(angleH, angleM),
							 360 - max(angleH, angleM) + min(angleH, angleM));
		}
		sort(c, c + 5, cmp); //排序
		printf("%02d:%02d\n", c[2].h, c[2].m);
	}
	return 0;
}

Keep up.

Published 138 original articles · won praise 1 · views 7003

Guess you like

Origin blog.csdn.net/Intelligence1028/article/details/104627759