All pastes #25119 Raw Edit

python eier (ikke)

public python v1 · immutable
#25119 ·published 2005-10-10 13:43 UTC
rendered paste body
from sys import stdindef merge(s1, s2):    inf = float(1e3000)    s = []    n1 = len(s1)    n2 = len(s2)    s1.append((inf,inf))    s2.append((inf,inf))    i = j = 0    a = s.append    for k in xrange(0, n1+n2):        (i1,x) = s1[i]        (i2,y) = s2[j]        if i1 < i2:            a(s1[i])            i += 1        else:            a(s2[j])            j += 1      return s       def main():    sr = []    sra = sr.append    for lj in stdin:        s = []        sa = s.append        ls = lj.split        for p in ls():            (t, b) = p.split(',')            t = int(t)            sa( (t, b) )        sra(s)          while len(sr) > 1:        s = []        for i in xrange(0, len(sr), 2):            if i + 1 == len(sr):                s.append(sr[i])            else:                s.append(merge(sr[i], sr[i+1]))        sr = s    print ''.join([b for (a,b) in sr[0]])    main()