题目:https://pintia.cn/problem-sets/994805260223102976/problems/994805304020025344
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
char jia[n];
char yi[n];
for(int i=0;i<n;i++)
{ getchar();
scanf("%c %c",&jia[i],&yi[i]);
}
int jia1[6]={};
int yi1[6]={};
for(int i=0;i<n;i++)
{
if(jia[i]==yi[i])
{
jia1[1]++;
yi1[1]++;
}
if(jia[i]=='C'&&yi[i]=='J')
{
jia1[0]++;
yi1[2]++;
jia1[3]++;
}
if(jia[i]=='C'&&yi[i]=='B')
{
jia1[2]++;
yi1[0]++;
yi1[5]++;
}
if(jia[i]=='B'&&yi[i]=='J')
{
jia1[2]++;
yi1[0]++;
yi1[4]++;
}
if(jia[i]=='B'&&yi[i]=='C')
{
jia1[0]++;
yi1[2]++;
jia1[5]++;
}
if(jia[i]=='J'&&yi[i]=='B')
{
jia1[0]++;
yi1[2]++;
jia1[4]++;
}
if(jia[i]=='J'&&yi[i]=='C')
{
jia1[2]++;
yi1[0]++;
yi1[3]++;
}
}
printf("%d %d %d\n",jia1[0],jia1[1],jia1[2]);
printf("%d %d %d\n",yi1[0],yi1[1],yi1[2]);
if(jia1[5]>=jia1[4]&&jia1[5]>=jia1[3])
{
printf("B ");
jia1[4]--;
jia1[3]--;
}
if(jia1[3]>=jia1[5]&&jia1[3]>=jia1[4])
{
printf("C ");
jia1[5]--;
jia1[4]--;
}
if(jia1[4]>=jia1[3]&&jia1[4]>=jia1[5])
{
printf("J ");
}
if(yi1[5]>=yi1[4]&&yi1[5]>=yi1[3])
{
printf("B");
yi1[4]--;
yi1[3]--;
}
if(yi1[3]>=yi1[5]&&yi1[3]>=yi1[4])
{
printf("C");
jia1[5]--;
jia1[4]--;
}
if(yi1[4]>=yi1[3]&&yi1[4]>=yi1[5])
{
printf("J");
}
return 0;
}
//菜鸡解法