# AtCoder Grand Contest 016

URL: https://atcoder.jp/contests/agc016/ (opens new window)

# A

s = gets.chomp

min = 100
# 最大26回
s.split("").uniq.each do |c|
  count = 0
  str = s.dup
  # cに全部変える操作を行う(ループは100回以下)
  while true do
    break if str.split("").uniq.length <= 1
    count += 1
    0.upto(s.length-2) do |i| # (ループは100回以下)
      if str[i] == c || str[i+1] == c
        str[i] = c
      end
    end
    str.chop! # 末尾削除
  end
  min = count if count < min
end
puts min
Last Updated: 2020/08/09 18:33