题解 | #坐标移动#

坐标移动

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

my_str = input().split(';')
start =[0,0]

for item in my_str:
    if not 2 <= len(item) <= 3:
        continue		#

    try:
        direction = item[0]
        step = int(item[1:])
        if direction in ['A','D','W','S']:
            if 0 <= step <= 99:
                if direction == 'A':
                    start[0] -= step
                elif direction == 'D':
                    start[0] += step
                elif direction == 'W':
                    start[1] += step
                elif direction == 'S':
                    start[1] -= step

    except:
        continue		#

print(str(start[0]) + ',' + str(start[1]))

全部评论

相关推荐

11-03 14:38
重庆大学 Java
AAA求offer教程:我手都抬起来了又揣裤兜了
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务