結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
31,088 KB
testcase_01 AC 41 ms
31,032 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 41 ms
31,548 KB
testcase_05 AC 41 ms
31,308 KB
testcase_06 AC 41 ms
31,180 KB
testcase_07 AC 41 ms
30,868 KB
testcase_08 AC 41 ms
30,908 KB
testcase_09 AC 42 ms
31,140 KB
testcase_10 AC 42 ms
31,144 KB
testcase_11 AC 41 ms
31,064 KB
testcase_12 AC 41 ms
31,192 KB
testcase_13 AC 41 ms
31,048 KB
testcase_14 AC 42 ms
31,508 KB
testcase_15 AC 42 ms
31,456 KB
testcase_16 AC 41 ms
31,120 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 43 ms
31,268 KB
testcase_20 AC 41 ms
31,268 KB
testcase_21 AC 44 ms
31,212 KB
testcase_22 AC 41 ms
30,912 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 42 ms
31,180 KB
testcase_29 AC 41 ms
31,396 KB
testcase_30 AC 41 ms
31,408 KB
testcase_31 AC 40 ms
31,312 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 = 0;

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