锤子剪子布

来源:互联网 发布:苏轼 柳永 知乎 编辑:程序博客网 时间:2024/04/30 08:52

题目描述

大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:


现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。


输入

输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。

输出

输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序最小的解。

样例输入

10C JJ BC BB BB CC CC BJ BB CJ J

样例输出

5 3 22 3 5B B
#include<cstdio>#include<iostream>#include<cstring>#include<cmath>#include<cstdlib>using namespace std;char _get(int c,int j,int b){int max=c;char temp='C';if(c<j){max=j;temp='J';if(max<=b)temp='B';//return temp;}else if(c<=b){max=b;temp='B';}return temp;}int main(){#ifdef ONLINE_JUDGE#elsefreopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#endifint n=0;cin>>n;int t1=0,t2=0,t3=0,t4=0,t5=0,t6=0,t7=0,t8=0,t9=0;for(int i=0;i<=n;i++){char a=' ',b=' ';//scanf("%c %c",&a,&b);cin>>a>>b;if(a=='C'){if(b=='C'){t1++;//ping}else if(b=='J'){t2++;//shengt4++;}else if(b=='B'){t3++;//shut7++;}}else if(a=='J'){if(b=='C'){t3++;//shut8++;}else if(b=='J'){t1++;//ping}else if(b=='B'){t2++;//shengt5++;}}else if(a=='B'){if(b=='C'){t2++;//shengt6++;}else if(b=='J'){t3++;//shut9++;}else if(b=='B'){t1++;//ping}}}cout<<t2<<' '<<t1<<' '<<t3<<endl;cout<<t3<<' '<<t1<<' '<<t2<<endl;char temp,temp1;temp=_get(t4,t5,t6);temp1=_get(t8,t9,t7);//order by c,j,bcout<<temp<<' '<<temp1<<endl;cin.get();return 0;}

原创粉丝点击