#include<iostream>#include<cstring>#include<algorithm>#include<map>usingnamespace std;intmain(){int n;
string str;
map<string,int> mp;
map<string,int>::iterator it;while(cin >> n){for(int i =0; i < n; i++){
cin >> str;
mp[str]=0;}int m;
cin >> m;int num;for(int i =0; i < m ; i++){int sum =1;for(int j =0; j < n; j++){
cin >> num >> str;
mp[str]+= num;}for( it = mp.begin(); it != mp.end(); it++){if(it->second > mp["memory"]) sum++;}
cout << sum << endl;}
mp.clear();}return0;}
例题2:A - 水果 HDU - 1263
#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<map>usingnamespace std;intmain(){
map<string,map<string,int>> mp ;
map<string,map<string,int>>::iterator it ;
map<string,int>::iterator t ;
string fruit , area ;int m , n ;int num ;
cin >> m ;while(m--){
cin >> n ;
mp.clear();while(n--){
cin >> fruit >> area >> num ;
mp[area][fruit]+= num ;}for( it = mp.begin(); it != mp.end(); it++){
cout << it -> first << endl ;for(t = it->second.begin(); t != it->second.end(); t++){
cout <<" |----"<< t -> first <<"("<< t -> second <<")"<< endl;}}if(m >0) cout << endl ;}return0;}
例题3:Language of FatMouse ZOJ - 1109
#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<map>#include<sstream>usingnamespace std;intmain(){
map<string,string> w ;char eng[30], mao[30];
string str ;while(getline( cin , str )){if( str.size()==0)break;
stringstream ss ;
ss << str ;
ss >> eng >> mao ;
w[mao]= eng ;}char v[30];while( cin >> v ){if( w.find(v)!= w.end()) cout << w[v]<< endl ;else cout <<"eh"<< endl ;}return0;}
例题4:Let the Balloon Rise HDU - 1004
#include<iostream>#include<algorithm>#include<cmath>#include<cstring>#include<map>usingnamespace std ;intmain(){
map<string,int> mp ;int n ;
string num , str ;while( cin >> n && n ){
mp.clear();for(int i =0; i < n ; i++){
cin >> num ;
mp[num]++;}int maxn =-1;
map<string,int>::iterator it ;for( it = mp.begin(); it != mp.end(); it++){if(( it -> second )> maxn){
maxn = it -> second ;
str = it -> first ;}}
cout << str << endl ;}}