题解 | #坐标移动#

坐标移动

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

str1 = input()
list1 = str1.split(';')
x = 0
y = 0
word2num = {'W':1,'S':-1,'A':-1,'D':1}  # 字典键值对用逗号分隔,不要用分号
for each in list1:
    if len(each) < 2:
        continue
    if each[1:].isdecimal():  # 字符串也可以切片
        if each[0] in ['A','D']:
            x += word2num[each[0]]*int(each[1:])
        elif each[0] in ['W','S']:
            y += word2num[each[0]]*int(each[1:])
print(x,y,sep=',')

全部评论

相关推荐

自来熟的放鸽子能手面...:这个不一定,找hr跟进一下
点赞 评论 收藏
分享
10-29 18:20
济南大学 Java
无语的太平湖水怪在看...:刷KPI的吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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