题解 | #坐标移动#

坐标移动

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

while True:
    try:
        input_list = input().split(';')             # 返回一个坐标列表
        initial = [0,0]                             # 初始化起始位置
        localdict = {'A':0,'D':0,'W':0,'S':0}       # 初始化坐标字典

        for i in input_list:
            if i == '':
                    continue
            elif i[0] not in localdict:
                continue
            elif len(i) > 3 or len(i) < 2:
                continue
            else:
                if len(i) == 2 :
                    if not('0' < i[1] <= '9'):
                        continue
                else:
                    if not ('0' < i[1]  <= '9'):
                        continue
                    elif '0' < i[1] <= '9':
                        if not ('0' <=i[2] <= '9'):
                            continue
                    else:
                        continue
            localdict[i[0]] += int(i[1:])
        localdict['X'] = localdict['D'] - localdict['A']
        localdict['Y'] = localdict['W'] - localdict['S']
        print('%d,%d'%(localdict['X'],localdict['Y']))

    except:
        break

全部评论

相关推荐

头像
09-29 16:18
门头沟学院 Java
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务