在一行上输入一个长度
,仅由可见字符构成的字符串
,代表输入的指令序列。
在一行上输出一个两个整数,代表小人最终位置的横纵坐标,使用逗号间隔。
A10;S20;W10;D30;X;A1A;B10A11;;A10;
10,-10
对于这个样例,我们模拟小人的移动过程:
第一个指令
是合法的,向左移动
个单位,到达
点;
第二个指令
是合法的,向下移动
个单位,到达
点;
第三个指令
是合法的,向上移动
个单位,到达
点;
第四个指令
是合法的,向右移动
个单位,到达
点;
第五个指令
不合法,跳过;
第六个指令
不合法,跳过;
第七个指令
不合法,跳过;
第八个指令
不合法,跳过;
第九个指令
是合法的,向左移动
个单位,到达
点。
ABC;AKL;DA1;
0,0
str1 = str(input()) str1_list = [i for i in str1.split(";") if len(i) != 0] str1_list = [i for i in str1_list if i[0] in ["A", "D", "W", "S"]] str2_list = [] for i in str1_list: try: if int(i[1:]) >= 1 and int(i[1:]) <= 99: str2_list.append(i) except: '' a, b = 0, 0 for i in str2_list: fx, val_ = i[0], int(i[1:]) if fx == "A": a -= val_ if fx == "D": a += val_ if fx == "W": b += val_ if fx == "S": b -= val_ print('{},{}'.format(a,b))
a = input().split(";") lis = ["W","A","S","D"] jihe = [] my_dict = { "W" : 0, "S" : 0, "A" : 0, "D" : 0 } for i in lis : for k in range(1,100): b = "" b = str(i) + str(k) jihe.append(b) for j in a: if j in jihe: c = j[1:] d = j[0] my_dict[d] += int(c) n,m = 0,0 n += my_dict["D"] n -= my_dict["A"] m += my_dict["W"] m -= my_dict["S"] print(str(n)+","+str(m))
instruct = input().split(';') position = [0, 0] for ins in instruct: l = ins[0:1] r = ins[1:] try: steps = eval(r) except: continue if l == 'A': position[0] -= steps elif l == 'S': position[1] -= steps elif l == 'D': position[0] += steps elif l == 'W': position[1] += steps print(position[0],end=',') print(position[1])
cord_list = input().split(';') x, y = 0, 0 for cord in cord_list: if 2 <= len(cord) <= 3 and cord[1:].isdigit(): d, step = cord[0], int(cord[1:]) if d == 'A': x -= step elif d == 'D': x += step elif d == 'W': y += step elif d == 'S': y -= step print(f'{x},{y}')
act=input().split(';') start=[0,0] for i in act: if not 2<=len(i)<=3: continue try: move=i[0] step=int(i[1:]) match (move): case "W": start[1]+=step case "S": start[1]-=step case "A": start[0]-=step case "D": start[0]+=step except: continue print(str(start[0])+','+str(start[1]))
s = input().split(';') x,y = 0,0 for move in s: if len(move) >= 2 and (move[1:]).isdigit(): if move[0] == 'A' : x -= int(move[1:]) elif move[0] == 'D' : x += int(move[1:]) elif move[0] == 'W' : y += int(move[1:]) elif move[0] == 'S' : y -= int(move[1:]) print(f'{x},{y}')
from ast import Pass while True: try: s = input().split(';') x, y = 0, 0 for move in s: if move == '': continue elif move[0] == 'A' and move[1:].isdigit(): x -= int(move[1:]) elif move[0] == 'W' and move[1:].isdigit(): y += int(move[1:]) elif move[0] == 'S' and move[1:].isdigit(): y -= int(move[1:]) elif move[0] == 'D' and move[1:].isdigit(): x += int(move[1:]) print(f'{x},{y}') except: break