classSheet(): def__init__(self, r, c) -> None: self.r = r self.c = c self.tbl = [[(i+1, j+1) for j inrange(c) ] for i inrange(r)] # 1-based, original position defDR(self, target): for i in target: self.tbl.pop(i) self.r -= len(target) defDC(self, target): for row in self.tbl: for j in target: row.pop(j) self.c -= len(target) defIR(self, target): for i in target: self.tbl.insert(i, [(0, 0) for _ inrange(self.c)]) self.r += len(target) defIC(self, target): for row in self.tbl: for j in target: row.insert(j, (0, 0)) self.c += len(target) defEX(self, pos): r1, c1, r2, c2 = pos self.tbl[r1][c1], self.tbl[r2][c2] = self.tbl[r2][c2], self.tbl[r1][c1] defquery(self, x, y): for i inrange(self.r): for j inrange(self.c): if self.tbl[i][j] == (x, y): return (i+1, j+1) return (0, 0)
kase = 1 whileTrue: r, c = map(int, input().split()) if r == 0and c == 0: break sheet = Sheet(r, c) n = int(input()) # number of operations for _ inrange(n): cmd, *args = input().split() args = list(map(lambda x: int(x)-1, args)) if cmd != "EX": # sort in descending order args = sorted(args[1:], reverse=True)
if cmd == "DR": sheet.DR(args) elif cmd == "DC": sheet.DC(args) elif cmd == "IR": sheet.IR(args) elif cmd == "IC": sheet.IC(args) elif cmd == "EX": sheet.EX(args) if kase > 1: print() print(f"Spreadsheet #{kase}") kase += 1 m = int(input()) # number of queries for _ inrange(m): x, y = map(int, input().split()) i, j = sheet.query(x, y) if i and j: print(f"Cell data in ({x},{y}) moved to ({i},{j})") else: print(f"Cell data in ({x},{y}) GONE")