题解 | #坐标移动#

坐标移动

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

l = list(input().strip().split(';'))

x, y = 0, 0
for s in l:
    if not 2 <= len(s) <= 3:
        continue
    if len(s) > 1 and s[0] in ['A', 'D', 'W', 'S']:
        if all(i in '0123456789' for i in s[1:]):
            step = int(s[1:])
            if s[0] == 'A': x -= step
            elif s[0] == 'D': x += step
            elif s[0] == 'W': y += step
            elif s[0] == 'S': y -= step

print('{},{}'.format(x, y))
全部评论

相关推荐

点赞 评论 收藏
分享
在写周报的打工人很独...:这个笔试昨天晚上做了一下,真难啊,前后端,ai全有
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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