sicily 1299 Academy Awards ——用map解决
//注意题目上说的:若词频相同,则想输出在表中先出现的那一个。因此要用一个记录容器vector
代码:
#include <iostream> #include <map> #include <vector> #include <string> using namespace std; int main() { int num; while(cin >> num && num != 0) { map<string,int> records; map<string,int>::iterator itr; vector<string> qq; while(num--) { string name; cin >> name; int filmnum; cin >> filmnum; while(filmnum--) { string temp; cin >> temp; qq.push_back(temp); records[temp]++; } } string maxstring; int max = 0; int i; for(i = 0;i < qq.size();i++) { itr = records.find(qq[i]); if(max<itr->second) { max = itr->second; maxstring = qq[i]; } } cout << maxstring << endl; } return 0; }