题解 | #坐标移动#

坐标移动

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

全部评论

相关推荐

_mos_:要不是看评论区我都不知道你要找的是数分
点赞 评论 收藏
分享
肖先生~:那年秋招闯进一位少年,人们都清楚:成功对他来说只是时间问题
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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