Skip to content

Instantly share code, notes, and snippets.

@LXZE
Created January 19, 2016 15:11
Show Gist options
  • Save LXZE/22597d3c103e90ad850f to your computer and use it in GitHub Desktop.
Save LXZE/22597d3c103e90ad850f to your computer and use it in GitHub Desktop.
review sequence
# f = open("in2.in","r")
f = open("review_input.txt","r")
w = open("output.txt","w")
num = f.readline()
for it in range(0,int(num)):
comment = [int(l) for l in f.readline().split()][1:]
comment.sort()
res = [ [comment[0],comment[0]] ]
bf = comment[0]
for i,num in enumerate(comment[1:]):
if num-bf > 1:
res.append([num,num])
else:
res[len(res)-1][1] = num
bf = num
r = ''
for tup in res:
r += ','
if tup[0] == tup[1]:
r += str(tup[0])
else:
r += '{0}->{1}'.format(str(tup[0]),str(tup[1]))
w.write("{0}\n".format(r[1:]))
w.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment