题解 | #坐标移动#

坐标移动

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

a = input().split(';')
axis = [0,0]
move_dict1 = {'A': -1, 'D': 1, 'W': 0, 'S': 0}
move_dict2 = {'A': 0,  'D': 0, 'W': 1, 'S': -1}
for i in a:
    try:
        move = i[0]
        length = int(i[1:])
        axis[0] += move_dict1[move] * length
        axis[1] += move_dict2[move] * length
    except:
        continue
print('{},{}'.format(axis[0],axis[1]))

全部评论

相关推荐

09-19 12:15
门头沟学院 Java
迷茫的大四🐶:这下是真的打牌了,我可以用感谢信和佬一起打牌吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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