h, w = gets.strip.split(' ').map(&:to_i) pos = [] (0...h).each do |y| s = gets.strip (0...s.length).each do |x| if s[x] =='*' pos << [x, y] end end end # p pos if pos[1][0] == pos[0][0] if pos[1][0] + 1 < w x = pos[1][0] + 1 else x = pos[1][0] - 1 end y = pos[1][1] elsif pos[1][1] == pos[0][1] if pos[1][1] + 1 < h y = pos[1][1] + 1 else y = pos[1][1] - 1 end x = pos[1][0] end pos << [x, y] # p pos (0...h).each do |y| (0...w).each do |x| if pos.include?([x, y]) print "*" else print "-" end end print "\n" end