题解 | #坐标移动#

坐标移动

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

# A10;S20;W10;D30;X;A1A;B10A11;;A10;
# A=左,D=右,W=向上,S=下

s = input().split(';')
start = [0,0]

for i in s:
    if not 2 <= len(i) <= 3:    #合法坐标为A(或者D或者W或者S) + 数字(两位以内)
        continue
    try:
        direction = i[0]
        step = int(i[1:])
        if direction in ['A','D','W','S']:
            if 0 <= step <= 99:
                if direction == 'A':
                    start[0] -=  step
                elif direction == 'D':
                    start[0] += step
                elif direction == 'W':
                    start[1] +=  step
                elif direction == 'S':
                    start[1] -= step
    except:
        continue
print(str(start[0]) + ',' + str(start[1]))


    


全部评论

相关推荐

不愿透露姓名的神秘牛友
06-27 18:00
点赞 评论 收藏
分享
小浪_Coding:找硬件测试,也可兼顾软测欧, 简历还可以的 ,注意排版,项目写的有条理一点, 然后个人技能多加点, 润色好简历之后就开始沟通海投了,深圳,东莞这边做硬件相关的公司还不少, 医疗类,仪器类的都可以尝试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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