結果

問題 No.345 最小チワワ問題
ユーザー peta727
提出日時 2016-05-12 14:14:10
言語 PHP
(843.2)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,919 bytes
コンパイル時間 902 ms
コンパイル使用メモリ 30,708 KB
実行使用メモリ 31,572 KB
最終ジャッジ日時 2024-10-07 16:20:49
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 23 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = [];
$min = strlen($str);

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