Created
January 12, 2011 16:24
-
-
Save nitinhayaran/776381 to your computer and use it in GitHub Desktop.
Solution for Studious Student Problem in Facebook Hacker Cup 2011 Qualification Round
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
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