2022-01-23 21:12

# pat乙1018 锤子剪刀布的问题，一个测试点怎么也过不了

5
），即双方交锋的次数。随后 N 行，每行给出一次交锋的信息，即甲、乙双方同时给出的的手势。C 代表“锤子”、J 代表“剪刀”、B 代表“布”，第 1 个字母代表甲方，第 2 个代表乙方，中间有 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<bits/stdc++.h>
using namespace std;

int maxNum(int a, int b, int c){
int maxnum = 0;
if (a > maxnum)
maxnum = a;
if (b > maxnum)
maxnum = b;
if(c > maxnum)
maxnum = c;
return maxnum;
}

int main(){
int N;
cin >> N;
char jia, yi;
int jwin = 0;
int ywin = 0;
int nowin = 0;
int jiac, jiaj, jiab, yic, yib, yij;
jiaj = jiac = jiab = yij = yib = yic = 0;

while(N--){
cin >> jia >> yi;
if(jia == 'J'){
if(yi == 'J') ++nowin;
if(yi == 'C') ++ywin, ++yic;
if(yi == 'B') ++jwin, ++jiaj;
}
else if(jia == 'C'){
if(yi == 'C') ++nowin;
if(yi == 'B') ++ywin, ++yib;
if(yi == 'J') ++jwin, ++jiac;
}
else if(jia == 'B'){
if(yi == 'B') ++nowin;
if(yi == 'J') ++ywin, ++yij;
if(yi == 'C') ++jwin, ++jiab;
}
}

cout << jwin << " " << nowin << " " << ywin << endl;
cout << ywin << " " << nowin << " " << jwin << endl;

int ans1 = maxNum(jiab, jiaj, jiac);
int ans2 = maxNum(yib, yij, yic);
if(ans1 == jiab) cout << "B";
else if(ans1 == jiaj) cout << "J";
else if(ans1 == jiac) cout << "C";

cout << " ";

if(ans2 == yib) cout << "B";
else if(ans2 == yij) cout << "J";
else if(ans2 == yic) cout << "C";

return 0;
}
``````