PTA乙级 (1018 锤子剪刀布 (20分))

锤子科技CEO 2020-02-01

1018 锤子剪刀布 (20分)

https://pintia.cn/problem-sets/994805260223102976/problems/994805304020025344

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	char chr1=‘C‘,chr2=‘J‘,chr3=‘B‘,c1,c2;
	int arr1[4]={0},arr2[4]={0};
	int win_1=0,equal_1=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>c1>>c2;
		if(c1==c2) equal_1++;
		else if((c1==‘B‘&&c2==‘C‘)||(c1==‘C‘&&c2==‘J‘)||(c1==‘J‘&&c2==‘B‘)) 
		{
			win_1++;
			if(c1==‘B‘) arr1[1]++;
			else if(c1==‘C‘) arr1[2]++;
			else if(c1==‘J‘) arr1[3]++;
		}
		else{
			if(c2==‘J‘) arr2[3]++;
			else if(c2==‘B‘) arr2[1]++;
			else if(c2==‘C‘) arr2[2]++;
		     } 
	}
	cout<<win_1<<" "<<equal_1<<" "<<n-win_1-equal_1<<endl;
	cout<<n-win_1-equal_1<<" "<<equal_1<<" "<<win_1<<endl;
	int max_1=0,max_2=0;
	for(int i=1;i<=3;i++)
	{
		if(arr1[i]>max_1) max_1=arr1[i];
		if(arr2[i]>max_2) max_2=arr2[i];
	}
	for(int i=1;i<=3;i++)
	{
		if(arr1[i]==max_1)
		{
			if(i==1) cout<<"B";
			else if(i==2) cout<<"C";
			else if(i==3) cout<<"J";
			break;
		}
	}
	for(int i=1;i<=3;i++)
	{
		if(arr2[i]==max_2)
		{
			if(i==1) cout<<" B";
			else if(i==2) cout<<" C";
			else if(i==3) cout<<" J";
			break;
		}
	}
	return 0;
}

相关推荐