Skip to content

Instantly share code, notes, and snippets.

@erukiti
Created May 27, 2012 12:32
Show Gist options
  • Save erukiti/2814046 to your computer and use it in GitHub Desktop.
Save erukiti/2814046 to your computer and use it in GitHub Desktop.
#! /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
@loveybot
Copy link

Yay Ruby!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment