题解 | #坐标移动#

坐标移动

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

用正则表达式来判断输入是否合法

import sys import re

p = r'[A|W|S|D]\d+' s = input().split(';') #print(s) instruct = [] data = [] for i in range(0,len(s)): pattern = re.compile(p) ins = pattern.findall(s[i]) if len(ins)!=0: if ins[0] == s[i]: instruct.append(ins[0][0]) data.append(int(ins[0][1:len(ins[0])])) #print(instruct) #print(data) x = 0 y = 0 for i in range(0,len(instruct)): if instruct[i]=='A': x = x-data[i] elif instruct[i]=='S': y = y-data[i] elif instruct[i]=='W': y = y+data[i] else: x = x+data[i] print(str(x)+','+str(y))

全部评论

相关推荐

WhiteAlbum...:学院本2中大厂垂直实习➕acm比赛 秋招0面试
点赞 评论 收藏
分享
在看牛客的社畜很积极:身高体重那一行信息去掉,学校那一行的信息放上面,找半天都没找到你是哪个学校什么专业的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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