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');