题解 | #坐标移动#

坐标移动

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

string = input()
groups = string.split(';')
count = []
for g in groups:
    if len(g) == 3 and g[1] >= '0' and g[1] <= '9' and g[2] >= '0' and g[2] <= '9':
        count.append(g)
    elif len(g) == 2 and g[1] >= '0' and g[1] <= '9':
        count.append(g)

l, r = 0, 0
for c in count:
    if c[0] == 'A':
        l -= int(c[1:])
    elif c[0] == 'D':
         l += int(c[1:])
    elif c[0] == 'W':
         r += int(c[1:])
    elif c[0] == 'S':
         r -= int(c[1:])

print(f'{l},{r}')

全部评论

相关推荐

LemontreeN:有的兄弟有的我今天一天面了五场,4个二面一个hr面
投递字节跳动等公司7个岗位
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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