Python正则 | #坐标移动#

坐标移动

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

inpt = input()
import re
strs = inpt.split(";")
A = 0
S = 0
W = 0
D = 0
c = ["A", "S", "W", "D"]
for i in strs:
    if re.findall(r"^A\d+$", i):
        A -= int(i[1:])
    if re.findall(r"^D\d+$", i):
        D += int(i[1:])
    if re.findall(r"^W\d+$", i):
        W += int(i[1:])
    if re.findall(r"^S\d+$", i):
        S -= int(i[1:])
print(str(A+D)+","+str(S+W))
全部评论

相关推荐

3 5 评论
分享
牛客网
牛客企业服务