View Code of Problem 100

#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<climits>
#include<cmath>
#include<unordered_map>
#include<set>

using namespace std;

bool cmp(pair<string, double> a, pair<string, double> b) {

	if (a.second > b.second)
		return true;
	else if (a.second == b.second)
		return a.first < b.first;

	return false;
}

int main()
{
	int n;
	while (cin >> n) {

		if (n == 0)
			break;

		unordered_map<string, double> map;
		unordered_map<string, double> songs;
		for (int i = 0; i < n; i++) {

			string name;
			int minute, second;
			cin >> name;
			scanf("%d:%d", &minute, &second);

			map[name] = minute * 60 + second;
		}

		int m;
		cin >> m;

		for (int i = 0; i < m; i++) {

			string name;
			int minute, second;
			cin >> name;
			scanf("%d:%d", &minute, &second);

			double sum = minute * 60 + second;

			if (sum < 0.2 * map[name])
				songs[name] += 0;
			else if(sum < 0.4 * map[name])
				songs[name] += 1;
			else if (sum < 0.6 * map[name])
				songs[name] += 2;
			else if (sum < 0.8 * map[name])
				songs[name] += 3;
			else if (sum < map[name])
				songs[name] += 4;
			else
				songs[name] += 5;
		}

		vector<pair<string, double>> res;

		for (auto item : songs) {

			res.push_back(make_pair(item.first, item.second));
		}

		sort(res.begin(), res.end(), cmp);

		for (int i = 0; i < res.size(); i++) {

			cout << res[i].first << " " << res[i].second << endl;
		}

	}
}

Double click to view unformatted code.


Back to problem 100