题解 | #坐标移动#

坐标移动

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]}')

全部评论

相关推荐

水墨不写bug:疑似没有上过大学
点赞 评论 收藏
分享
07-22 11:07
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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