题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
# print("请输入:") str=input() j=0 x=0 y=0 for i in range(len(str)): if str[i]==';': j+=1 # print(j) str = str.split(';') for i in range(j): # if str[i][0]=='W' or str[i][0]=='S' or str[i][0]=='A' or str[i][0]=='D': if len(str[i])==2 and ((str[i][1])>='0' and (str[i][1])<='9'): # print('str[i] 2:',str[i]) if(str[i][0]=='W'): y += int(str[i][1]) elif str[i][0]=='S': y -= int(str[i][1]) elif str[i][0]=='A': x -= int(str[i][1]) elif str[i][0]=='D': x += int(str[i][1]) if len(str[i])==3 and ((str[i][1])>='0' and (str[i][1])<='9' and (str[i][2])>='0' and (str[i][2])<='9'): # print('str[i] 3:',str[i]) if(str[i][0]=='W'): y += int(str[i][1])*10+int(str[i][2]) elif str[i][0]=='S': y -= int(str[i][1])*10+int(str[i][2]) elif str[i][0]=='A': x -= int(str[i][1])*10+int(str[i][2]) elif str[i][0]=='D': x += int(str[i][1])*10+int(str[i][2]) print('{},{}'.format(x,y))写的比较基础,欢迎交流#力扣刷题#