[PAT解题报告] 锤子剪刀布 (20)

```#include <iostream>
#include <algorithm>

int comp(char a, char b) {
if(a == b) return 0;
if( ('C' == a && 'J' == b) ||
('J' == a && 'B' == b) ||
('B' == a && 'C' == b)
)
return 1;
return -1;
}

int mapping(char c) {
if('B' == c) return 0;
if('C' == c) return 1;
return 2; // 'J'
}

char maxChar(int chArray[3]) {
int maxV = *std::max_element(chArray, chArray + 3);
if(chArray[0] == maxV)
return 'B';
if(chArray[1] == maxV)
return 'C';
return 'J';
}

int main() {
int n;
std::cin >> n;
char a, b;
int iCountWin = 0;
int iCoundEven = 0;
int cnt1[3] = {0, 0, 0};
int cnt2[3] = {0, 0, 0};

for(int i = 0; i < n; ++i) {
std::cin >> a >> b;
int ret = comp(a, b);
if(1 == ret) {
++iCountWin;
++cnt1[mapping(a)];
}
else if(0 == ret)
++iCoundEven;
else {
++cnt2[mapping(b)];
}
}
std::cout << iCountWin << ' ' << iCoundEven << ' ' << n - iCoundEven - iCountWin << std::endl;
std::cout << n - iCoundEven - iCountWin << ' ' << iCoundEven << ' ' << iCountWin << std::endl;
std::cout << maxChar(cnt1) << ' ' << maxChar(cnt2) << std::endl;
return 0;
}
```

2022-12-31 16:55

2022-12-14 23:54

2022-12-12 18:42

2022-12-13 10:19

2022-12-27 18:33

2022-12-23 00:18

01-16 10:27

2022-12-15 20:08

2022-12-19 22:57