题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String str = in.nextLine(); String[] strs = str.split(";"); int x = 0; int y = 0; for (int i = 0; i < strs.length; i++) { String m = strs[i]; if (m.length() > 3 || m.length() <= 1) { continue; } int num = 0; if (m.length() == 2) { if (Character.isDigit(m.charAt(1))) { num = Integer.parseInt(m.substring(1)); } else { continue; } } if (m.length() == 3) { if (Character.isDigit(m.charAt(1)) && Character.isDigit(m.charAt(2))) { num = Integer.parseInt(m.substring(1, 3)); } else { continue; } } if (m.charAt(0) == ('A')) { x -= num; } if (m.charAt(0) == ('S')) { y -= num; } if (m.charAt(0) == ('W')) { y += num; } if (m.charAt(0) == ('D')) { x += num; } } System.out.print(x + "," + y); } }