注意点:
字典序:预定义一个mp
循环类取余判断输赢
输入样例
10
C J
J B
C B
B B
B C
C C
C B
J B
B C
J J
输出样例
5 3 2
2 3 5
B B
C++代码
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef pair<int, int> PII;
typedef long long LL;
// 按字典序大小返回
int change(char c ) {
if ( c == 'B' ) return 0;
if ( c == 'C' ) return 1;
if ( c == 'J' ) return 2;
}
int main()
{
char mp[3] = {'B','C','J'}; // 字典序
int n;
cin >> n;
int t1[3] = {0}, t2[3] = {0};
int h1[3] = {0}, h2[3] = {0};
char c1,c2;
int k1,k2;
while( n -- ) {
getchar();
scanf("%c %c", &c1, &c2);
// 转换为数字
k1 = change(c1);
k2 = change(c2);
// 取余判断!!
if ((k1+1) % 3 == k2 ) {
t1[0]++, t2[2]++, h1[k1]++;
}
else if ( k1 == k2 ) {
t1[1]++, t2[1]++;
}
else {
t1[2]++;
t2[0]++;
h2[k2]++;
}
}
cout << t1[0] << " " << t1[1] << " " << t1[2] << endl;
cout << t2[0] << " " << t2[1] << " " << t2[2] << endl;
int id1 = 0, id2 = 0;
for ( int i=0; i<3; i++ ) {
if ( h1[i] > h1[id1] ) id1 = i;
if ( h2[i] > h2[id2] ) id2 = i;
}
cout << mp[id1] << " " << mp[id2] << endl;
return 0;
}