Beta Round #67-B: Facetook Priority Wall

解法

問題文がちゃんと読めたらやるだけっぽい。

#include <cstdio>
#include <sstream>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

string myName;

int main(){
	getline(cin,myName);
	int N;
	cin >> N;
	cin.ignore();
	map<string, int> dict;
	for(int i=0; i<N; i++){
		string line;
		getline(cin, line);
		for(int i=0; i<line.length(); i++){
			if(line[i] == '\''){
				line[i] = ' ';
			}
		}
		stringstream ss(line);
		vector<string> ws;
		string str;
		while(ss>>str) ws.push_back(str);
		if(ws[1] == "posted"){
			string a = ws[0], b = ws[3];
			dict[a] += 0; dict[b] += 0;
			if(a == myName || b == myName){
				dict[a] += 15;
				dict[b] += 15;
			}
		}
		else if(ws[1] == "commented"){
			string a = ws[0], b = ws[3];
			dict[a] += 0; dict[b] += 0;
			if(a == myName || b == myName){
				dict[a] += 10;
				dict[b] += 10;
			}
		}
		else if(ws[1] == "likes"){
			string a = ws[0], b = ws[2];
			dict[a] += 0; dict[b] += 0;
			if(a == myName || b == myName){
				dict[a] += 5;
				dict[b] += 5;
			}
		}
	}
	vector<pair<int, string> > ans;
	for(typeof(dict.begin()) itr = dict.begin(); itr != dict.end(); itr++){
		if(itr->first != myName){
			ans.push_back( make_pair(-(itr->second), itr->first));
		}
	}
	sort(ans.begin(), ans.end());
	for(int i=0; i<ans.size(); i++){
		cout << ans[i].second << endl;
	}
	return 0;
}