题解 | #坐标移动#

坐标移动

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

import sys
import re

pos = [0,0]
for line in sys.stdin:
    a = line.split(';')
    for item in a:
        #print('item=',item)
        if re.match(r'(\d+)$',item[1:]):
            #print('item=',item[0],':',[item[1:]])
            if item[0] == 'A':
                pos[0] -= int(item[1:])
            elif item[0] == 'D':
                pos[0] += int(item[1:])
            elif item[0] == 'S':
                pos[1] -= int(item[1:])
            elif item[0] == 'W':
                pos[1] += int(item[1:])     
print(pos[0],pos[1],sep=',')

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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