题解 | #坐标移动#

坐标移动

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

receive = input().split(";")
x,y=0,0
for i in receive:
    if 1<len(i)<=3:
        condition=i[1:]
        if condition.isdigit():
            if i[0]=='A':
               x-=1*int(condition) 
            if i[0]=='D': 
               x+=1*int(condition) 
            if i[0]=='S': 
                y-=1*int(condition) 
            if i[0]=='W': 
                y+=1*int(condition) 
print(str(x)+','+str(y))

Python isdigit() 方法检测字符串是否只由数字组成,只对 0 和 正数有效。

str.isdigit()

如果字符串只包含数字则返回 True 否则返回 False。

全部评论

相关推荐

Aaso:挺好的,早挂早超生
点赞 评论 收藏
分享
04-15 23:42
中山大学 Java
搞Java不如组一辈子乐队:接好运
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务