题解 | 坐标移动
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.*; import java.util.regex.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String[] stss = in.nextLine().split(";"); int sumY = 0, sumX = 0; for (String e : stss) { Pattern pattern = Pattern.compile("[ASWD]([1-9]\\d?)"); Matcher matcher = pattern.matcher(e); if (matcher.matches()) { char chc = e.charAt(0); int ini = Integer.parseInt(e.substring(1)); if (e.charAt(0) == 'A') { sumX -= ini; } else if (e.charAt(0) == 'D') { sumX += ini; } else if (e.charAt(0) == 'W') { sumY += ini; } else if (e.charAt(0) == 'S') { sumY -= ini; } } } System.out.print(sumX + "," + sumY); } }