题解 | #坐标移动#

坐标移动

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

import sys

ASWD = input().split(';')

def move(direction,x,y):
    if len(direction) <2 or direction[:1] not in ['A','S','W','D']:
        return (x,y)
    elif direction[1:].isdigit():
        if direction[0:1] == 'A':
            x -= int(direction[1:])
        if direction[0:1] == 'S':
            y -= int(direction[1:])
        if direction[0:1] == 'W':
            y += int(direction[1:])
        if direction[0:1] == 'D':
            x += int(direction[1:])
    return x,y

x,y = 0 ,0
for i in ASWD:
    x,y = move(i,x,y)
print(f"{x},{y}")

全部评论

相关推荐

09-23 08:41
已编辑
门头沟学院 Java
牛客吹哨人:可恶!它越来越嚣张了...哨哥晚点统一更新到黑名单:能救一个是一个!26届毁意向毁约裁员黑名单https://www.nowcoder.com/discuss/1525833
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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