题解 | #坐标移动#

坐标移动

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}")

全部评论

相关推荐

05-19 15:21
已编辑
华南农业大学 Java
白火同学:你才沟通了200,说实话,北上广深杭这里面你连一座城市的互联网公司都没投满呢,更别说还有各种准一线二线城市了。等你沟通突破了三位数,还没结果再考虑转行的事吧。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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