def change(line) j = 0 count = 0 while true return count if j == line.length if line[j] == "B" && line[j + 1] == "A" line[j] = "A" line[j + 1] = "B" count += 1 end j += 1 end end line = gets.chomp.split("") count = 0 line.length.times{ count += change(line) } puts count