题解 | #坐标移动#

坐标移动

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))

全部评论

相关推荐

迷qwq:比我本科强多了,找个不错的工作问题不大,更好的工作就得看面试表现加上运气了。另外自身经历不错,简历写的不太好,再润色一下。
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务