【问题描述】
大家应该都会玩“锤子剪刀布”的游戏。现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
【输入形式】
输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。
【输出形式】
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序最小的解。
【样例输入】
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
#include <iostream>
#include <map>
using namespace std;
int main() {
int n, win1 = 0, draw1 = 0, lose1 = 0;
map<char, int> m1 = {{'C', 0},
{'B', 0},
{'J', 0}}, m2 = m1;
char c1, c2, res1 = 'B', res2 = 'B';
cin >> n;
while (n--) {
cin >> c1 >> c2;
if (c1 == c2) draw1++;
else if ((c1 == 'C' && c2 == 'J') || (c1 == 'J' && c2 == 'B') || (c1 == 'B' && c2 == 'C')) {
m1[c1]++;
win1++;
} else if ((c1 == 'J' && c2 == 'C') || (c1 == 'B' && c2 == 'J') || (c1 == 'C' && c2 == 'B')) {
m2[c2]++;
lose1++;
}
}
cout << win1 << " " << draw1 << " " << lose1 << endl << lose1 << " " << draw1 << " " << win1 << endl;
int max = 0;
for (const auto &item: m1) {
if (item.second > max) {
max = item.second;
res1 = item.first;
}
}
max = 0;
for (const auto &item: m2) {
if (item.second > max) {
max = item.second;
res2 = item.first;
}
}
cout << res1 << " " << res2;
return 0;
}