n, m = map(int, input().split()) kafelki = {} for y in range(n): r = input() for x, e in enumerate(r): if e != ".": kafelki[(x, y)] = e k = int(input()) instrukcje = input() last = None for i in instrukcje: if i != last: if i == "G": kolumny = {} for pos in kafelki: e = kafelki[pos] if pos[0] in kolumny: kolumny[pos[0]].append(e) else: kolumny[pos[0]] = [e] kafelki = {} for k in kolumny: for num, e in enumerate(kolumny[k]): kafelki[(k, num)] = e elif i == "D": kolumny = {} for pos in kafelki: e = kafelki[pos] if pos[0] in kolumny: kolumny[pos[0]].append(e) else: kolumny[pos[0]] = [e] kafelki = {} for k in kolumny: for num, e in enumerate(kolumny[k][::-1]): kafelki[(k, n-num-1)] = e elif i == "L": wiersze = {} for pos in kafelki: e = kafelki[pos] if pos[1] in wiersze: wiersze[pos[1]].append(e) else: wiersze[pos[1]] = [e] kafelki = {} for w in wiersze: for num, e in enumerate(wiersze[w]): kafelki[(num, w)] = e elif i == "P": wiersze = {} for pos in kafelki: e = kafelki[pos] if pos[1] in wiersze: wiersze[pos[1]].append(e) else: wiersze[pos[1]] = [e] kafelki = {} for w in wiersze: for num, e in enumerate(wiersze[w][::-1]): kafelki[(m-num-1, w)] = e last = i for y in range(n): for x in range(m): if (x, y) in kafelki: print(kafelki[(x, y)], end = "") else: print(".", end="") print()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | n, m = map(int, input().split()) kafelki = {} for y in range(n): r = input() for x, e in enumerate(r): if e != ".": kafelki[(x, y)] = e k = int(input()) instrukcje = input() last = None for i in instrukcje: if i != last: if i == "G": kolumny = {} for pos in kafelki: e = kafelki[pos] if pos[0] in kolumny: kolumny[pos[0]].append(e) else: kolumny[pos[0]] = [e] kafelki = {} for k in kolumny: for num, e in enumerate(kolumny[k]): kafelki[(k, num)] = e elif i == "D": kolumny = {} for pos in kafelki: e = kafelki[pos] if pos[0] in kolumny: kolumny[pos[0]].append(e) else: kolumny[pos[0]] = [e] kafelki = {} for k in kolumny: for num, e in enumerate(kolumny[k][::-1]): kafelki[(k, n-num-1)] = e elif i == "L": wiersze = {} for pos in kafelki: e = kafelki[pos] if pos[1] in wiersze: wiersze[pos[1]].append(e) else: wiersze[pos[1]] = [e] kafelki = {} for w in wiersze: for num, e in enumerate(wiersze[w]): kafelki[(num, w)] = e elif i == "P": wiersze = {} for pos in kafelki: e = kafelki[pos] if pos[1] in wiersze: wiersze[pos[1]].append(e) else: wiersze[pos[1]] = [e] kafelki = {} for w in wiersze: for num, e in enumerate(wiersze[w][::-1]): kafelki[(m-num-1, w)] = e last = i for y in range(n): for x in range(m): if (x, y) in kafelki: print(kafelki[(x, y)], end = "") else: print(".", end="") print() |