大家应该都会玩“锤子剪刀布”的游戏:两人同时给出手势,胜负规则如图所示:
现给出两人的交锋记录,请统计双方的胜、平、负次数,并且给出双方分别出什么手势的胜算最大。
输入格式:
输入第 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
<?php
$num = trim(fgets(STDIN));
$num =(integer)$num;
//读入
$win =array("C J","J B","B C");
$pin = array("B B","C C","J J");
$A = array("B"=>0,"C"=>0,"J"=>0);
$B = array("B"=>0,"C"=>0,"J"=>0);
$scoreA = array("w"=>0,"p"=>0,"f"=>0 );
$scoreB = array("w"=>0,"p"=>0,"f"=>0 );
$MAX = $NN = $MM = $MAA = null;
for($i = 0 ; $i < $num ; $i++){
$sca = trim(fgets(STDIN));
if(in_array($sca,$win)){
$A[substr($sca,0,1)]+=1;
$scoreA["w"] +=1;
$scoreB["f"] +=1;
}else if(in_array($sca,$pin)){
$scoreA["p"] +=1;
$scoreB["p"] +=1;
}else{
$B[substr($sca,2,1)]+=1;
$scoreA["f"] +=1;
$scoreB["w"] +=1;
}
}
//输出
foreach ($scoreA as $key => $val) {
echo $val;
if($key != "f"){
echo " ";
}
}
echo "\n";
foreach ($scoreB as $key => $val) {
echo $val;
if($key != "f"){
echo " ";
}
}
echo "\n";
foreach ($A as $key => $val) {
if($val > $MAX){
$MAX = $val;
$NN = $key;
}
}
if($NN == null){
echo "B";
}else{
echo $NN;
}
echo " ";
foreach ($B as $key => $val) {
if($val > $MAA){
$MAA = $val;
$MM = $key;
}
}
if($MM == null){
echo "B";
}else{
echo $MM;
}
?>