Skip to content

Instantly share code, notes, and snippets.

@okaq
Created May 13, 2011 01:13
Show Gist options
  • Save okaq/969780 to your computer and use it in GitHub Desktop.
Save okaq/969780 to your computer and use it in GitHub Desktop.
Solution: GoroSort (Google Code Jam 2011 Qualification Round Problem D)
import sys
fin = file(sys.argv[1])
fout = open(sys.argv[2], 'w')
lines = fin.readlines()
goros0 = [map(int, line.split()) for line in lines]
goros = []
tests = goros0.pop(0)
for i in range(1, len(goros0), 2):
goros.append(goros0[i])
data = []
for i in range(len(goros)):
sg = list(goros[i])
sg.sort()
c0 = 0
for j in range(len(goros[i])):
if (sg[j] != goros[i][j]):
c0 += 1
data.append(c0)
for i in range(len(data)):
fout.write("Case #%d: %d\n" % ((i + 1), data[i]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment