题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextLine()) { String ll = in.nextLine(); String[] lines = ll.split(";"); int x = 0; int y = 0; for (String line : lines) { if (line.matches("[ASWD][0-9]{1,2}")) { char oriention = line.charAt(0); int value = Integer.parseInt(line.substring(1)); switch (oriention) { case 'A': x -= value; break; case 'W': y += value; break; case 'S': y -= value; break; case 'D': x += value; break; } } } System.out.println(x + "," + y); } } }