现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入格式:
输入第 1 行给出正整数 N(≤10
5
),即双方交锋的次数。随后 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<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;
}
代码差两分满分,但是实在不知道怎么改,希望大家帮助下,谢谢!