题解 | 坐标移动

import re
pattern = r'^[ASDW]\d+$'
a = input().split(';')
position = [0,0]
for i in a:
    match = re.match(pattern , i)
    if match:
        if i[0] == "A":
            position[0] -= int(i[1:])
        if i[0] == "D":
            position[0] += int(i[1:])
        if i[0] == "S":
            position[1] -= int(i[1:])
        if i[0] == "W":
            position[1] += int(i[1:])
result = ",".join(str(item) for item in position)
print(result)


全部评论

相关推荐

LemontreeN:有的兄弟有的我今天一天面了五场,4个二面一个hr面
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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