C++版浙大PAT乙级1018(20分)
作者:互联网
https://pintia.cn/problem-sets/994805260223102976/problems/994805304020025344
这题思路有的,就是要注意细节。
#include<iostream>
#include <string.h>
using namespace std;
int a1=0, a2=0, b1=0, b2=0;
int a_arr[3], b_arr[3];
char ch[3]={'C','J','B'};
int biggest(int arr[], int len){
int max=-1, max_index=-1;
for(int i=0; i<len; i++){
if(arr[i]>max || (arr[i] == max && ch[i] < ch[max_index])){
max = arr[i];
max_index = i;
}
}
return max_index;
}
void winner(char j, char y){
if(j=='C' && y=='J'){
a_arr[0]++;
a1 ++;
b2 ++;
}else if(j=='J' && y=='B'){
a_arr[1]++;
b2 ++;
a1 ++;
}else if(j=='B' && y=='C'){
a_arr[2]++;
b2 ++;
a1 ++;
}else if(j=='J' && y=='C'){
b1 ++;
a2 ++;
b_arr[0]++;
}else if(j=='B' && y=='J'){
a2 ++;
b1 ++;
b_arr[1]++;
}else if(j=='C' && y=='B'){
a2 ++;
b1 ++;
b_arr[2]++;
}
}
int main(){
int n;
char a, b;
cin >> n;
for(int i=0; i<n; i++){
cin >> a >> b;
winner(a, b);
}
cout << a1 << " " << n-a1-a2 << " " << a2 << endl;
cout << b1 << " " << n-b1-b2 << " " << b2 << endl;
cout << ch[biggest(a_arr, 3)] << " " << ch[biggest(b_arr, 3)];
return 0;
}
标签:arr,20,++,max,C++,else,int,1018,&& 来源: https://blog.csdn.net/qq_33514421/article/details/113777361