Created
December 7, 2013 14:04
-
-
Save inage/7841759 to your computer and use it in GitHub Desktop.
Best Cow Line (POJ 3617)
This file contains hidden or 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
| ## Best Cow Line (POJ 3617) | |
| ## http://rubyfiddle.com/riddles/f878f | |
| s = "ACDBCB" | |
| n = s.length #文字の長さ。"ACDBCB"の場合は6。 | |
| t = "" | |
| i=0 | |
| loop do | |
| break if s.size == 1 | |
| case s[0..i] <=> s[s.size-1-i..s.size-1] | |
| when 1 | |
| t += s.slice!(s.size-1-i..s.size-1).reverse | |
| i=0 | |
| when -1 | |
| t += s.slice!(0..i) | |
| i=0 | |
| when 0 | |
| i += 1 | |
| end | |
| end | |
| puts t+s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment