Last active
May 26, 2019 11:08
-
-
Save soscler/3748de5f0ed4049d6ea1f43ec414e92d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python3 solution.py < input_file.txt > output_file.txt # To redirect the input and output to a file | |
# input() reads a string with a line of input, stripping the ' ' (newline) at the end. | |
# This is all you need for most Code Jam problems. | |
t = int(input()) # read a line with a single integer | |
for i in range(1, t + 1): | |
n, r, c, sr, sc = [int(s) for s in input().split(" ")] # read a list of integers, 2 in this case | |
tr = sr | |
tc = sc | |
positions = {} | |
array = list(input()) # read integer of the form 012345 and return a list [0, 1, 2, 3, 4, 5] | |
positions[str(tr)+':'+str(tc)] = 1; | |
for j in range(len(array)): | |
mvt = array[j] | |
if mvt == 'E': | |
while(positions.get(str(tr) +":"+ str(tc + 1), 0 ) == 1): | |
tc = tc + 1 | |
tc + tc +1 | |
elif mvt == 'W': | |
while(positions.get(str(tr)+':'+str(tc - 1), 0) == 1): | |
tc = tc - 1 | |
tc = tc - 1 | |
elif mvt == 'N': | |
while(positions.get(str(tr - 1)+':'+str(tc), 0) == 1): | |
tr = tr -1 | |
tr = tr - 1 | |
elif mvt == 'S': | |
while(positions.get(str(tr + 1)+':'+str(tc), 0) == 1): | |
tr = tr + 1 | |
tr = tr+ 1 | |
positions[str(tr)+':'+str(tc)] = 1; | |
print("Case #{}: {} {}".format(i, tr, tc)) | |
# check out .format's specification for more formatting options |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment