Skip to content

Instantly share code, notes, and snippets.

@nitinhayaran
Created January 12, 2011 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nitinhayaran/776381 to your computer and use it in GitHub Desktop.
Save nitinhayaran/776381 to your computer and use it in GitHub Desktop.
Solution for Studious Student Problem in Facebook Hacker Cup 2011 Qualification Round
import sys
def func(stings):
strings.sort(compare)
return ''.join(strings)
def compare(x,y):
if(x.find(y) == 0 or y.find(x) == 0):
return cmp(x+y,y+x)
return cmp(x,y)
def main(filename):
f = open(filename, 'r')
s = f.readlines()
for i in s[1:]:
strings = i.split(' ')
strings = [k.strip() for k in strings[1:]]
print func(strings)
if __name__ == '__main__':
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment