結果
| 問題 | 
                            No.345 最小チワワ問題
                             | 
                    
| コンテスト | |
| ユーザー | 
                             peta727
                         | 
                    
| 提出日時 | 2016-05-12 13:50:14 | 
| 言語 | PHP  (843.2)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,678 bytes | 
| コンパイル時間 | 2,327 ms | 
| コンパイル使用メモリ | 32,016 KB | 
| 実行使用メモリ | 32,660 KB | 
| 最終ジャッジ日時 | 2024-10-05 13:57:04 | 
| 合計ジャッジ時間 | 2,428 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 20 WA * 9 | 
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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');
            
            
            
        
            
peta727