#!/usr/bin/python3 # Posune souřadnice v odpovídajícím směru. # Nekontroluje, zda-li to je možné (zeď, kraj mapy…) def forward(pos, d): if d == 0: return (pos[0], pos[1] + 1) if d == 1: return (pos[0] + 1, pos[1]) if d == 2: return (pos[0], pos[1] - 1) if d == 3: return (pos[0] - 1, pos[1]) # Je na tyto souřadnice možné vstupit? def empty(mapIn, pos): # Ne, protože to je za krajem mapy if pos[0] < 0 or pos[1] < 0 or pos[0] >= len(mapIn) or pos[1] >= len(mapIn[0]): return False # Podle toho, zda tam je zeď return mapIn[pos[0]][pos[1]] != "#" # Provede jeden krok dozorce. def step(mapIn, pos, d): newPos = forward(pos, d) # Pokud by došel na prázdné políčko, udělá to if empty(mapIn, newPos): return (newPos, d) # jinak se otočí else: return (pos, (d + 1) % 4) [n, m, k] = list(map(int, input().split())) mapIn = [] mapOut = [] # Načteme vstup for i in range(n): line = input() mapIn.append(line) # Překopírujeme stěny do výstupu for line in mapIn: outLine = [] for char in line: if char == "#": outLine.append("#") else: outLine.append(".") mapOut.append(outLine) # Pro každé políčko mapy… for i in range(n): for j in range(m): # …přeskočíme jej, pokud na něm nestojí dozorce if mapIn[i][j] == "#" or mapIn[i][j] == ".": continue # …převedeme si orientaci dozorce na číslo if mapIn[i][j] == '>': turtleD = 0 elif mapIn[i][j] == 'V': turtleD = 1 elif mapIn[i][j] == '<': turtleD = 2 elif mapIn[i][j] == 'A': turtleD = 3 # *Pos je dvojice čísel značící souřadnice # *D je čislo označující orientaci turtlePos = (i, j) hareD = turtleD harePos = turtlePos # kolik kroků již udělala želva t = 0 while True: t += 1 (turtlePos, turtleD) = step(mapIn, turtlePos, turtleD) (harePos, hareD) = step(mapIn, harePos, hareD) if t != 1 and turtlePos == harePos and turtleD == hareD: t = t + ((k-t) // (t-1)) * (t-1) (harePos, hareD) = step(mapIn, harePos, hareD) if t == k: break if turtlePos == harePos and turtleD == hareD: t = ((k-1) // t) * t # na konečných souřadnicích želvy zůstane stát dozorce # zapišeme si jej do výstupní mapy mapOut[turtlePos[0]][turtlePos[1]] = "X" for line in mapOut: # line je seznam, ale print vypisuje stringy # slepíme tedy jednotlivé prvky pole k sobě # a vypíšeme print("".join(line))