题解 | #坐标移动#

坐标移动

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

s=input()
l=s.split(';')

x,y=0,0 #初始化x,y
for i in l:
    flag=0# 用来判断数字是否合规
    if len(i) not in [2,3]:
        continue
    direction=i[0]
    dis=i[1:]
    try:
        dis=int(dis)
        flag=1#数字合规
    except:
        flag=0#数字不合规
    if flag==1:
        if direction=='A':
            x-=dis
        elif direction=='S':
            y-=dis
        elif direction=='W':
            y+=dis
        elif direction=='D':
            x+=dis
ans=''+str(x)+','+str(y)
print(ans)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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