题目链接
https://www.nowcoder.com/pat/6/problem/4044
代码
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#define MAX 105
typedef struct Game{
char one;
char two;
} game;
int main() {
int n;
game games[MAX];
int a[6], b[6];
int pos[2];
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(pos, 0, sizeof(pos));
scanf("%d", &n);
for(int i=0; i<n; i++) {
cin >> games[i].one >> games[i].two;
if(games[i].one == games[i].two) {
a[1]++;
b[1]++;
}else if( (games[i].one == 'B' && games[i].two == 'C')||(games[i].one == 'C' && games[i].two == 'J')||(games[i].one == 'J' && games[i].two == 'B') ) {
if(games[i].one == 'B') a[3]++;
else if(games[i].one == 'C') a[4]++;
else a[5]++;
a[0]++;
b[2]++;
}
else{
if(games[i].two == 'B') b[3]++;
else if(games[i].two == 'C') b[4]++;
else b[5]++;
a[2]++;
b[0]++;
}
}
for(int i=0; i<2; i++) {
printf("%d ", a[i]);
}
printf("%d\n", a[2]);
for(int i=0; i<2; i++) {
printf("%d ", b[i]);
}
printf("%d\n", b[2]);
pos[0] = max_element(a+3, a+6) - a - 3;
pos[1] = max_element(b+3, b+6) - b -3;
for(int i=0; i<2; i++) {
if(pos[i] == 0) printf("B");
else if(pos[i] == 1) printf("C");
else printf("J");
if(i == 0) printf(" ");
}
return 0;
}