結果

問題 No.345 最小チワワ問題
ユーザー peta727peta727
提出日時 2016-05-12 14:00:45
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,745 bytes
コンパイル時間 1,843 ms
コンパイル使用メモリ 30,728 KB
実行使用メモリ 31,440 KB
最終ジャッジ日時 2024-04-15 15:18:10
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
31,064 KB
testcase_01 AC 45 ms
31,140 KB
testcase_02 AC 45 ms
31,080 KB
testcase_03 AC 44 ms
30,892 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 41 ms
30,948 KB
testcase_08 AC 41 ms
30,964 KB
testcase_09 AC 42 ms
31,004 KB
testcase_10 AC 41 ms
31,064 KB
testcase_11 AC 41 ms
31,092 KB
testcase_12 AC 42 ms
30,956 KB
testcase_13 AC 41 ms
30,784 KB
testcase_14 AC 41 ms
30,856 KB
testcase_15 AC 41 ms
31,288 KB
testcase_16 AC 41 ms
30,920 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 41 ms
30,920 KB
testcase_20 AC 41 ms
30,776 KB
testcase_21 AC 41 ms
31,080 KB
testcase_22 AC 41 ms
31,188 KB
testcase_23 AC 41 ms
30,860 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 41 ms
30,888 KB
testcase_28 AC 41 ms
30,880 KB
testcase_29 AC 40 ms
31,240 KB
testcase_30 WA -
testcase_31 AC 41 ms
31,008 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

/*
* Input/Output用のクラス
*/

namespace Coder;

class IO
{
    private $raw = [];
    private $count = 0;
    private $pointer = 0;

    /*
     * デリミタで区切った文字列を取得する
     * @param string
     * @return string
     */
    public function next($del = ' ') {
        if ($this->pointer >= $this->count) {
            $this->raw = explode("{$del}", trim(fgets(STDIN)));
            $this->count = count($this->raw);
            $this->pointer = 0;
        }
        $result = $this->raw[$this->pointer];
        $this->pointer++;
        return $result;
    }
    /*
     * 次にまだ文字列があるかを調べる
     * @return bool
     */
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    /*
     * int型で文字列を取り出す
     * @return int
     */
    public function nextInt($del = ' ') {
        return (int)$this->next($del);
    }
    /*
     * double型で文字列を取り出す
     * @return double
     */
    public function nextDouble($del = ' ') {
        return (double)$this->next($del);
    }
    /*
     * 改行を末尾に追加して出力する
     * @param string
     */
    public static function out ($str = '') {
        echo $str . PHP_EOL;
    }
}

$io = new IO();

$str = $io->next();
$count_c = 0;
$count_w = 0;
$index = -1;

for($i = 0; $i < strlen($str); $i++) {
    if ($str[$i] == 'c') {
        if ($i - $index >= 3 || $index == -1) {
            $count_w = 0;
            $index = $i;
        }
        $count_c = 1;
    }
    if ($str[$i] == 'w') {
        $count_w++;
        if ($count_c == 1 && $count_w == 2) {
            $io->out($i - $index + 1);
            exit;
        }
    }
}
$io->out('-1');
0