题解 | #坐标移动#

坐标移动

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

move_list = input()
move_list=move_list.split(";")


def coor_move(m_list):
    result = [0, 0]
    action_map = {"A": [-1, 0], "D": [1, 0], "W": [0, 1], "S": [0, -1]}#省的一个个if else

    for act in m_list:
        flag = islegal(act)
        if flag:
            result = [i + j*flag for i, j in zip(result, action_map[act[0]])]
    print(str(result[0])+","+str(result[1]))
   


def islegal(str1):
    if len(str1) > 3 or not str1 :
        return False
    if 90 < ord(str1[0]) or  ord(str1[0])< 65:
        return False
    if str1[1:].isdigit():
        return int( str1[1:])
    return False


coor_move(move_list)

全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务