题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
def get_ans(s):
if not s: return
x,y,li=0,0,s.split(';')
for item in li:
try:
direction,step=item[0],item[1:]
if direction=='A': x-=int(step)
if direction=='D': x+=int(step)
if direction=='W': y+=int(step)
if direction=='S': y-=int(step)
except:
continue
return x,y
if __name__=='__main__':
import sys
lines = []
while True:
line = sys.stdin.readline().strip()
if line == "":
break
lines.append(line)
for item in lines:
print('{},{}'.format(get_ans(item)[0],get_ans(item)[1]))
题解-数据结构与算法 文章被收录于专栏
小菜鸟的题解