题解 | #坐标移动#

坐标移动

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

import sys

    

m=list(input().split(';'))



p,q=0,0

for i in m:   
    if len(i)>=2:
        if str(i[0]) in 'WASD':
            if str(i[1]) in '0123456789'  :
                if len(i)==2:
                    if str(i[0])=='A':
                        p-= int(i[1:])
                    if str(i[0])=='D':
                        p+= int(i[1:])
                    if str(i[0])=='W':
                        q+=int(i[1:])
                    if str(i[0])=='S':
                        q-=int(i[1:])
                else:
                    if str(i[2]) in '0123456789' or i[2]==None:
                        if str(i[0])=='A':
                            p-= int(i[1:])
                        if str(i[0])=='D':
                            p+= int(i[1:])
                        if str(i[0])=='W':
                            q+=int(i[1:])
                        if str(i[0])=='S':
                            q-=int(i[1:])
                    
l=str(p)+','+str(q)   
                    
print(l)

全部评论

相关推荐

专心打鱼:互联网搬运工,贴子都要偷
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务