题解 | #坐标移动#

坐标移动

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

str = input().split(';') # 使用;分开

x = 0
y = 0


for i in range(len(str)):
    cmd = list(str[i])
    # print(cmd)
    if 1< len(cmd) <4: #根据题目要求可以知道我们需要的长度范围
        if cmd[0] == 'A':
            try: #这里是出现A9A这样的情况的处理,如果无法转换就跳过
                x -= int(str[i].replace('A','',1)) #将字母替换为空,就是除去了字母
            except:
                continue
        elif cmd[0] == 'D':
            try:
                x += int(str[i].replace('D','',1))
            except:
                continue
        elif cmd[0] == 'W':
            try:
                y += int(str[i].replace('W','',1))
            except:
                continue
        elif cmd[0] == 'S':
            try:
                y -= int(str[i].replace('S','',1))
            except:
                continue
print('{},{}'.format(x,y)) # 最后使用格式化输出
全部评论

相关推荐

昨天 18:30
门头沟学院 Java
点赞 评论 收藏
分享
见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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