题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int[] res = new int[]{0,0}; List<String> str = new ArrayList<String>(); while(sc.hasNext()){ String s = sc.nextLine(); int slen = s.length(); StringBuffer sb = new StringBuffer(); for(int k = 0;k < slen;k++){ if(s.charAt(k) != ';'){ sb.append(s.charAt(k)); }else{ str.add(sb.toString()); sb = new StringBuffer(); } } int len = str.size(); for(int i = 0;i < len;i++){ if(str.get(i) == null){ continue; } int m = str.get(i).length(); if(m == 0 || m == 1) continue; char ch = str.get(i).charAt(0); if(!(ch == 'A' || ch == 'W' || ch == 'S' || ch == 'D')) continue; int count = 0; for(int j = 1;j < m;j++){ if(!Character.isDigit(str.get(i).charAt(j))){ count = 0; break; } count = count * 10 + str.get(i).charAt(j) - '0'; } if(ch == 'A'){ res[0] -= count; }else if(ch == 'D'){ res[0] += count; }else if(ch == 'W'){ res[1] += count; }else if(ch == 'S'){ res[1] -= count; } } System.out.print(res[0] + "," + res[1]); } } }