Hangzhou Electric OJ 1177 (C ++)

Basic questions, structure sorted.

First number is read by solving all players and, when converted to a second.

Then sort, not the same number of problem solving, the number of problem solving top surface; the same number of problem solving when using a small top surface.

Finally, according to the number of bronze and gold and silver ranking players decide where output.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int MAXN = 135;

struct participant //参赛选手
{
	int solve; //解题数量
	int time; //用时
	int num; //序号
}p[MAXN];

//排序条件,解题数量不同时,解题数量多的排在前面
//解题数量相同时,用时少的排在前面
bool cmp(participant p1, participant p2)
{
	if (p1.solve != p2.solve)
		return p1.solve > p2.solve;
	else
		return p1.time < p2.time;
}

int main()
{
	int N, G, S, C, M;
	while (cin >> N >> G >> S >> C >> M)
	{
		if (N == 0 && G == 0 && S == 0 && C == 0 && M == 0)
			break;
		string str; //时间字符串
		int h, m, s; //时,分,秒
		for (int i = 1; i <= N; i++)
		{
			cin >> p[i].solve >> 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');
			p[i].time = h * 3600 + m * 60 + s;
			p[i].num = i;
		}
		sort(p + 1, p + N + 1, cmp); //排序
		for (int i = 1; i <= N; i++)
		{
			if (p[i].num == M)
			{
				if (i <= G)
					cout << "Accepted today? I've got a golden medal :)" << endl;
				else if (i <= G + S)
					cout << "Accepted today? I've got a silver medal :)" << endl;
				else if (i <= G + S + C)
					cout << "Accepted today? I've got a copper medal :)" << endl;
				else
					cout << "Accepted today? I've got an honor mentioned :)" << endl;

				break;
			}
		}
	}
	return 0;
}

Keep up.

Published 138 original articles · won praise 1 · views 7023

Guess you like

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