SPOJ TOANDFRO

Example solution in Python 2.5: 

while 1: cols = int(raw_input) if not cols: exit st = raw_input b = [st[i*cols:i*cols+cols] for i in xrange(len(st)/cols)] for i in xrange(len(b[:])): if i % 2: b[i] = b[i][::-1] print .join([.join(x) for x in zip(*b)])

