题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#-*- coding:utf-8 -*- #自己实现的代码,逻辑应该是清晰的,但是比较繁琐 # string = list(input().strip().split(';')) # i,j = 0,0 # #合法字符串 # move_str = ['A','D','W','S'] # digit = [str(i) for i in range(100)] # leg_list = [] # for m in move_str: # for dig in digit: # leg_list.append(m + dig) # for s in string: # if s not in leg_list: #非法字符直接跳过 # continue # else: #对合法字符进行判断并移动 # if s[0] == 'A': # i -= int(s[1:]) # if s[0] == 'S': # j -= int(s[1:]) # if s[0] == 'W': # j += int(s[1:]) # if s[0] == 'D': # i += int(s[1:]) # print(str(i) + ',' + str(j)) #整合优秀题解代码——简短代码 string = list(input().strip().split(';')) dic = {'A':0,'S':0,'W':0,'D':0} for s in string: try: #利用try...except...进行判断分析 pos = int(s[1:]) dic[s[0]] += pos except: continue print(str(dic['D'] - dic['A']) + ',' + str(dic['W'] - dic['S'])) #一步到位进行坐标计算