题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

from re import I
import sys

#for line in sys.stdin:
#    a = line.split()
#    print(int(a[0]) + int(a[1]))

#L=[]
L=input().split(";")
direction=[]
distance=[]
#print(L)
for x in L:
    if x!="":
        if x[0] in "WSAD" and (x[1:]).isdigit():
            direction.append(x[0])
            distance.append(int(x[1:]))
        else:
            pass
#print(direction)
#print(distance)
#l=zip(direction,distance)
x=0
y=0
for i,j in zip(direction,distance):
#    print(i,j)
    if i=="A":
#        print("**********************")
        x=x-j
#        print(x)
    if i=="D":
        x=x+j
    if i=="W":
        y=y+j
    if i=="S":
        y=y-j
print(x,y ,sep=",")

全部评论

相关推荐

榕城小榕树:1200单休,我去干点啥别的不好
点赞 评论 收藏
分享
下北澤大天使:你是我见过最美的牛客女孩😍
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务