Created
May 27, 2012 12:32
-
-
Save erukiti/2814046 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
#! /usr/bin/env ruby | |
# coding: utf-8 | |
words = [] | |
n = STDIN.gets.strip.to_i | |
(0 ... n).each do | |
words << STDIN.gets.strip | |
end | |
words = words.sort do |a, b| | |
n = 1 | |
result = 0 | |
loop do | |
a_chr = a[-n .. -n] | |
b_chr = b[-n .. -n] | |
if a_chr == nil | |
result = -1 | |
break | |
end | |
if b_chr == nil | |
result = 1 | |
break | |
end | |
if a_chr != b_chr | |
result = a_chr <=> b_chr | |
break | |
end | |
n += 1 | |
end | |
result | |
end | |
words.each do |word| | |
puts word | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yay Ruby!!