题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
line = input('', 's'); line_sp = strsplit(line,';'); str_all = 'ASWD'; left_1 = 0; right_1 = 0; for ii = 1 : length(line_sp) line_now = line_sp{ii}; line_char = char(line_now); if isempty(line_char) else if length(line_now) < 4 line_now_fang = line_char(1); [ind] = strfind(str_all,line_now_fang); if isempty(ind) else line_now_yidong = line_char(2:end); line_yi = str2num(line_now_yidong); if isempty(line_yi) else if line_now_fang == 'A' left_1 =left_1 - line_yi; end if line_now_fang == 'D' left_1 =left_1 + line_yi; end if line_now_fang == 'S' right_1 =right_1 - line_yi; end if line_now_fang == 'W' right_1 =right_1 + line_yi; end end end end end end printf("%d,%d", left_1,right_1)