1018. 锤子剪刀布 (20)
时间限制
100 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue
大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:

现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入格式:
输入第1行给出正整数N(<=105),即双方交锋的次数。随后N行,每行给出一次交锋的信息,即甲、乙双方同时给出的的手势。C代表“锤子”、J代表“剪刀”、B代表“布”,第1个字母代表甲方,第2个代表乙方,中间有1个空格。
输出格式:
输出第1、2行分别给出甲、乙的胜、平、负次数,数字间以1个空格分隔。第3行给出两个字母,分别代表甲、乙获胜次数最多的手势,中间有1个空格。如果解不唯一,则输出按字母序最小的解。
输入样例:10 C J J B C B B B B C C C C B J B B C J J输出样例:
5 3 2 2 3 5 B B
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int com(char a,char b){
if(a==b) return 0;
if(a=='C'){
if(b=='J') return 1;
else return -1;
}
if(a=='J'){
if(b=='B') return 1;
else return -1;
}
if(a=='B'){
if(b=='C') return 1;
else return -1;
}
}
int main()
{
char a,b;
int ac,aj,ab,bc,bj,bb;
int n,i,res;
int win(0),lose(0),ping(0);
ac=aj=ab=bc=bj=bb=0;
cin>>n;
while(n){
cin>>a>>b;
res=com(a,b);
if(res==0) ping++;
else if(res==1) {
win++;//a
if(a=='J') aj++;
else if(a=='B') ab++;
else ac++;
}
else{
lose++;//b
if(b=='J') bj++;
else if(b=='B') bb++;
else bc++;
}
n--;
}
cout<<win<<" "<<ping<<" "<<lose<<"\n";
cout<<lose<<" "<<ping<<" "<<win<<"\n";
if(ab>=ac){
if(ab>=aj) cout<<"B";
else cout<<"J";
}else{
if(ac>=aj) cout<<"C";
else cout<<"J";
}
cout<<" ";
if(bb>=bc){
if(bb>=bj) cout<<"B";
else cout<<"J";
}else{
if(bc>=bj) cout<<"C";
else cout<<"J";
}
cout<<"\n";
return 0;
}
Sume: 简便的思路?