# coding: utf-8 text = gets.chomp text = text.gsub(/^w+/, "") w_array = text.scan(/w+/) if text == "" or w_array.length == 0 p "" return 0 end max_w = w_array.sort_by(&:length).last.length for word in text.scan(/[^w]+[w]{#{max_w}}/) p word.gsub(/[w]+/, "") end