Skip to content

Instantly share code, notes, and snippets.

@soscler
Last active May 26, 2019 11:08
Show Gist options
  • Save soscler/3748de5f0ed4049d6ea1f43ec414e92d to your computer and use it in GitHub Desktop.
Save soscler/3748de5f0ed4049d6ea1f43ec414e92d to your computer and use it in GitHub Desktop.
# 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