Created
January 5, 2016 13:35
-
-
Save chuck0523/1841b447b99816f58dcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patern = [ | |
['a', 'b', 'c'], | |
['b', 'c', 'a'], | |
['c', 'a', 'b'] | |
] | |
n = gets.to_i | |
str = gets | |
if n % 2 === 0 || str[str.length / 2 - 1] != 'b' | |
puts -1 | |
exit | |
end | |
n.times do |t| | |
if str[t] != patern[n % 3][t % 3] | |
puts -1 | |
exit | |
end | |
end | |
puts str.length / 2 - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment