22-1 unordered_map+结构体重载
//unordered_map
//结构体+重载<
//for(auto t:cnt)遍历unordered_map
#include<iostream>
#include<algorithm>
#include<cstring>
#include<unordered_map>
using namespace std;
unordered_map<char,int> cnt;
unordered_map<char,string> mp{{'b',"blue"},
{'r',"red"},
{'g',"green"},
{'p',"purple"}};
const int N=35;
int n;
//int cnt[N];
struct plane
{
char c;
int num;
bool operator < (const plane &t)const
{
return num > t.num;
}
}p[N];
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>p[i].c>>p[i].num;
// if(p[i].c=='b') cnt[0]++;
// if(p[i].c=='g') cnt[1]++;
// if(p[i].c=='p') cnt[2]++;
// if(p[i].c=='r') cnt[3]++;
cnt[p[i].c]++;
}
sort(p,p+n);
// cout<<"blue"<<" "<<cnt[0]<<endl;
// cout<<"green"<<" "<<cnt[1]<<endl;
// cout<<"purple"<<" "<<cnt[2]<<endl;
// cout<<"red"<<" "<<cnt[3]<<endl;
for(auto t:cnt)
{
cout<<mp[t.first]<<" "<<t.second<<endl;
}
cout<<endl;
for(int i=0;i<n;i++)
{
cout<<p[i].num<<" "<<mp[p[i].c]<<endl;
}
return 0;
}