题解 | #坐标移动#

坐标移动

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

str1 = input()
str1 = str1.split(";")
start = [0,0]
for i in range(len(str1)):
    if len(str1[i]) > 3 or len(str1[i]) <= 1 or str1[i][2:3].isalpha() or str1[i][1:2].isalpha():
        continue
    else:
        oper, step = str1[i][0:1], int(str1[i][1:])
        if oper == 'A':
            start = [start[0]-step,start[1]]
        elif oper == 'D':
            start = [start[0]+step,start[1]]
        elif oper == 'S':
            start = [start[0], start[1]-step]
        elif oper == 'W':
            start = [start[0], start[1] + step]
        else:
            continue
        
print(",".join(str(i) for i in start))

简单且暴力的方法

全部评论

相关推荐

对空六翼:你真幸运,碰见这么好的人,不像我,秋招的时候被室友骗进cx了
实习好累,可以辞职全力准...
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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