36 lines
987 B
Python
36 lines
987 B
Python
import sys
|
|
import numpy
|
|
|
|
|
|
def main():
|
|
inp_stacks, inp_moves = (x.split("\n") for x in sys.stdin.read().split("\n\n", 1))
|
|
|
|
rows = (line[1::4] for line in inp_stacks[::-1] if "[" in line)
|
|
stacks = [
|
|
numpy.array([ord(c) for c in x if c != " "], dtype=numpy.int8)
|
|
for x in zip(*rows)
|
|
]
|
|
stacks1 = numpy.array(stacks)
|
|
stacks2 = numpy.ndarray.copy(stacks1)
|
|
|
|
for i, line in enumerate(inp_moves):
|
|
if i % 10000 == 0:
|
|
print(i, len(inp_moves), end="\r")
|
|
if not line:
|
|
continue
|
|
|
|
_, a, _, b, _, c = line.split()
|
|
n, f, t = int(a), int(b) - 1, int(c) - 1
|
|
|
|
stacks1[t] = numpy.concatenate((stacks1[t], stacks1[f][-n:][::-1]))
|
|
stacks1[f] = stacks1[f][:-n]
|
|
|
|
stacks2[t] = numpy.concatenate((stacks2[t], stacks2[f][-n:]))
|
|
stacks2[f] = stacks2[f][:-n]
|
|
|
|
print("".join(chr(s[-1]) for s in stacks1), "".join(chr(s[-1]) for s in stacks2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|