题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
str = input().split(';') # 使用;分开
x = 0
y = 0
for i in range(len(str)):
cmd = list(str[i])
# print(cmd)
if 1< len(cmd) <4: #根据题目要求可以知道我们需要的长度范围
if cmd[0] == 'A':
try: #这里是出现A9A这样的情况的处理,如果无法转换就跳过
x -= int(str[i].replace('A','',1)) #将字母替换为空,就是除去了字母
except:
continue
elif cmd[0] == 'D':
try:
x += int(str[i].replace('D','',1))
except:
continue
elif cmd[0] == 'W':
try:
y += int(str[i].replace('W','',1))
except:
continue
elif cmd[0] == 'S':
try:
y -= int(str[i].replace('S','',1))
except:
continue
print('{},{}'.format(x,y)) # 最后使用格式化输出