题目不难 就是要仔细

坐标移动

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

while True:
    try:
        pos = [0,0]
        s = input().split(';')
        for op in s:
            if len(op) == 0:
                 continue
            elif len(op)==1:
                 continue
            elif len(op)>1:
                if not op[0].isalpha():
                    continue
                else:
                    op_direction = op[0]
                    step = ''
                    for i in op[1:]:
                        if i.isdigit():
                            step += i 
                        else:
                            break
                    if len(step)>=1:
                        step = int(step)
                    else:
                        continue
                    if op_direction == 'W':
                        pos[1] += step
                    elif op_direction == 'S':
                        pos[1] -= step
                    elif op_direction == 'A':
                        pos[0] -= step
                    elif op_direction == 'D':
                        pos[0] += step
        print('{},{}'.format(pos[0],pos[1]))
    except:
        break


全部评论

相关推荐

_mos_:要不是看评论区我都不知道你要找的是数分
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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