题解 | #坐标移动#
坐标移动
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=',')
老板电器公司氛围 197人发布
查看14道真题和解析