题解 | #坐标移动#

坐标移动

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

import re
cmds = input().split(';')
res = [0,0]

for i in cmds:
    ret = re.match(pattern='^[AWSD][0-9]{1,2}$',string=i)
    if not ret:
        continue
    else:
        i = ret.group()
    # print(i)
    if i[0]=='A':
        res[0]-=int(i[1:])
    elif i[0]=='D':
        res[0]+=int(i[1:])
    elif i[0]=='W':
        res[1]+=int(i[1:])
    elif i[0]=='S':
        res[1]-=int(i[1:])
print(res[0],res[1],sep=',')

全部评论

相关推荐

04-21 11:22
已编辑
中华女子学院 UE4
点赞 评论 收藏
分享
刘湘_passion:太强了牛肉哥有被激励到
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务