题解 | #坐标移动#

坐标移动

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

import sys

input_list = input().split(';')
initial = [0,0]

for i in input_list:
    if not 2 <= len(i) <= 3:
        continue

    try:
        direction = i[0]
        step = int(i[1:])
        if direction in ['A','S','W','D']:
            if 0 <= step <= 99:
                if direction == 'A':
                    initial[0] -= step
                elif direction == 'D':
                    initial[0] += step
                elif direction == 'S':
                    initial[1] -= step
                elif direction == 'W':
                    initial[1] += step
    except:
        continue
                
print(f'{initial[0]},{initial[1]}')

全部评论

相关推荐

投递腾讯等公司10个岗位
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务