結果

問題 No.161 制限ジャンケン
コンテスト
ユーザー papinianus
提出日時 2016-09-28 14:56:39
言語 PHP
(8.5.4)
コンパイル:
php -l _filename_
実行:
php _filename_
結果
AC  
実行時間 33 ms / 5,000 ms
コード長 1,442 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,569 ms
コンパイル使用メモリ 37,888 KB
実行使用メモリ 38,264 KB
最終ジャッジ日時 2026-05-23 21:44:41
合計ジャッジ時間 5,141 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #
raw source code

<?php
list($g, $c, $p) = explode(" ",trim(fgets(STDIN)));
$hands = array_count_values(str_split(trim(fgets(STDIN))));
$first = [];
$win = 0;
$even = 0;
foreach($hands as $hand => $times)
{
    switch($hand)
    {
        case "G":
            while($p && $times)
            {
                $times--;
                $p--;
                $win++;
            }
            $first["G"] = $times;
            break;
        case "C":
            while($g && $times)
            {
                $times--;
                $g--;
                $win++;
            }
            $first["C"] = $times;
            break;
        case "P":
            while($c && $times)
            {
                $times--;
                $c--;
                $win++;
            }
            $first["P"] = $times;
            break;
    }
}
foreach($first as $hand => $times)
{
    switch($hand)
    {
        case "G":
            while($g && $times)
            {
                $times--;
                $g--;
                $even++;
            }
            break;
        case "C":
            while($c && $times)
            {
                $times--;
                $c--;
                $even++;
            }
            break;
        case "P":
            while($p && $times)
            {
                $times--;
                $p--;
                $even++;
            }
            break;
    }
}
echo $win*3+$even;
echo PHP_EOL;
0