import sys
for line in sys.stdin:
a = line.split("\n")[0]
ops = a.split(";")
x = y = 0
for op in ops:
if not op:
continue
if op[0] not in {'W', 'A', 'S', 'D'}:
continue
# WASD仅能有一个,否则不合法
flag = False
for i in range(1,len(op),1):
if op[i] in {'W', 'A', 'S', 'D'}:
flag = True
break
if flag:
continue
try:
if op[0] == 'W':
count = int(op.split("W")[1])
if count > 99 or count < 1:
continue
y += count
elif op[0] == 'S':
count = int(op.split("S")[1])
if count > 99 or count < 1:
continue
y -= count
elif op[0] == 'A':
count = int(op.split("A")[1])
if count > 99 or count < 1:
continue
x -= count
elif op[0] == 'D':
count = int(op.split("D")[1])
if count > 99 or count < 1:
continue
x += count
except:
continue
print("%s,%s" % (x, y))
遍历,判断几次是否合法,然后模拟上下左右即可

京公网安备 11010502036488号