杭州エレクトリックOJ 1177(C ++)

基本的な質問、構造がソートされました。

最初の数は、第二に変換されたとき、すべてのプレイヤーを解くとによって読み取られます。

次に、ソート、問題解決のない同じ数、問題解決の最表面の数、問題解決の同じ数の小さな上面を使用。

最後に、ブロンズと金と銀の順位のプレイヤーの数に応じてどこの出力を決定します。

#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;
}

続けてください。

公開された138元の記事 ウォンの賞賛1 ビュー7023

おすすめ

転載: blog.csdn.net/Intelligence1028/article/details/104561814