题解 | 坐标移动

坐标移动

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

import sys
import re

m=list(input().split(';'))
x,y=0,0
for step in m:
    if re.fullmatch(r'([ADWS]{1})(\d+)',step):
        d=step[0]
        s=int(step[1:])
        if 0<s<100:
            if d == 'A':
                x=x-s
            elif d == 'D':
                x=x+s
            elif d == 'W':
                y=y+s
            elif d == 'S':
                y=y-s
print('{},{}'.format(x,y))



全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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