题解 | #坐标移动#

坐标移动

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

思路分析:存下输入进行切片后遍历判断是否满足条件: wsad开头数字结尾长度2~3位,字典存下其变化最后相加减得出最终位置。

inputs1 = sys.stdin.readline().strip()
list1 = inputs1.split(';')
dict1 = {'W':0,'S':0,'A':0,'D':0}
for i in list1:
    if len(i)>3 or len(i)<2 or i[0] not in dict1 or not i[1:].isdigit():
        continue
    else:
        dict1[i[0]] += int(i[1:])
print(str(dict1['D']-dict1['A']) + ',' + str(dict1['W']-dict1['S']))
全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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