PAT (Basic Level) Practice(中文)1018 锤子剪刀布 (20 分)
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
using namespace std;
typedef pair<char,int> PII;
int n,cnt;
map<char,int>m1,m2;
char a,b;
bool cmp(PII a,PII b)
{
if(a.second!=b.second)return a.second>b.second;
else return a.first<b.first;
}
int main()
{
cin>>n;
//m1['C']=m1['B']=m1['J']=0;
//m2['C']=m2['B']=m2['J']=0;
while(n--)
{
cin>>a>>b;
if(a==b)cnt++;
if(a=='C'&&b=='J')m1['C']++;
if(a=='J'&&b=='B')m1['J']++;
if(a=='B'&&b=='C')m1['B']++;
if(b=='C'&&a=='J')m2['C']++;
if(b=='J'&&a=='B')m2['J']++;
if(b=='B'&&a=='C')m2['B']++;
}
int awin=m1['C']+m1['B']+m1['J'];
int bwin=m2['C']+m2['B']+m2['J'];
cout<<awin<<' '<<cnt<<' '<<bwin<<endl;
cout<<bwin<<' '<<cnt<<' '<<awin<<endl;
//转移map的全部数据到vector
vector<PII>v1(m1.begin(),m1.end());
vector<PII>v2(m2.begin(),m2.end());
//对vector自定义排序
sort(v1.begin(),v1.end(),cmp);
sort(v2.begin(),v2.end(),cmp);
cout<<v1.front().first<<' '<<v2.front().first<<endl;
return 0;
}