现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入格式:
输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。
输出格式:
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序最小的解。
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int change (char a)
{
switch (a)
{
case 'B':return 0;
case 'C':return 1;
case 'J':return 2;
}
}
int main ()
{
int num;
scanf("%d",&num);
char hand[3]={'B','C','J'};
char first,second;
int k1,k2;
int times[3]={0},sort1[3]={0},sort2[3]={0};
for(int i=0;i<num;i++)
{
cin>>first;
cin>>second;
k1=change(first);
k2=change(second);
if( (k1+1)%3==k2)
{
times[0]++;
sort1[k1]++;
}
else if(k1==k2)
{
times[1]++;
}
else if( (k2+1)%3==k1)
{
times[2]++;
sort2[k2]++;
}
}
printf("%d %d %d\n",times[0],times[1],times[2]);
printf("%d %d %d\n",times[2],times[1],times[0]);
int j1=0,j2=0;
for(int i=0;i<3;i++)
{
if(sort1[i]>sort1[j1]) j1=i;
if(sort2[i]>sort2[j2]) j2=i;
}
printf("%c %c\n",hand[j1],hand[j2]);
system("pause");
return 0;
}