結果

問題 No.345 最小チワワ問題
ユーザー harhogefoo
提出日時 2016-10-18 08:30:14
言語 Ruby
(3.4.1)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 360 bytes
コンパイル時間 313 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-09-25 11:54:15
合計ジャッジ時間 3,862 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:21: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

s = gets.chomp

min = 1000

s.length.times do |i|
  w_flag = false
  if s[i] == 'c'
    (i..(s.length)).each do |j|
      if s[j] == 'w' and not w_flag
        w_flag = true
      elsif s[j] == 'w' and w_flag
        length = j - i + 1
        min = length if length < min
        break
      end
    end
  end
end

if min == 1000
  puts -1
else
  puts min
end
0