题解 | 坐标移动

坐标移动

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

小模拟题

推荐使用py来写,方便快捷,可以直接指定输入用";"来分割,省去了很多不必要的操作

commands = input().split(";")
x, y = 0, 0

for cmd in commands:
    if len(cmd) < 2 or len(cmd) > 3:
        continue
    c = cmd[0]
    if c not in "ADWS":
        continue
    p = cmd[1:]
    if p.isdigit() and 1 <= int(p) <= 99:
        p = int(p)
        if c == "A":
            x -= p
        elif c == "D":
            x += p
        elif c == "W":
            y += p
        elif c == "S":
            y -= p

print(f"{x},{y}")

 每日一题攒牛币,大厂offer不是梦,点我马上开始赚牛币

#牛客春招刷题训练营#

全部评论

相关推荐

点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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