题解 | #坐标移动#

坐标移动

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

# A10;S20;W10;D30;X;A1A;B10A11;;A10;
s = input()
list_str = s.split(';')
x = 0
y = 0
direction_zy = {"A": -1, "D": 1}
direction_sx = {"W": 1, "S": -1}
direction = dict(direction_zy)
direction.update(direction_sx)
for i in range(len(list_str)-1):
    str = list_str[i]
    if len(str)==0 or len(str)>3:
        continue
    if str[0] not in direction.keys():
        continue
    try:
        number = int(str[1:])
    except:
        number = -1
    if number>=0:
        if str[0] in direction_sx.keys():
            y = y + direction[str[0]] * number
        else:
            x = x + direction[str[0]] * number
print(f'{x},{y}')
渣渣的写法,哈哈,打卡的第一题,留个笔
#字节测试开发一面面经#
全部评论

相关推荐

牛客刘北:如果暑期实习是27届的话,你要晚一年才会毕业,企业为什么会等你呢?要搞清时间逻辑呀!27届现在实习只能是在暑假实习,这是日常实习,不是暑期实习。所以多去投日常实习吧,暑期实习肯定不会要你的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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