题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String[] values = scanner.nextLine().split(";"); int[] point = new int[]{0, 0}; for (String value : values) { if (value.length() > 3) { continue; } // 判断后两位是不是数字 int i; try { i = Integer.parseInt(value.substring(1)); } catch (Exception e) { continue; } switch (value.charAt(0)) { case 'A': point[0] -= i; break; case 'S': point[1] -= i; break; case 'D': point[0] += i; break; case 'W': point[1] += i; break; default: break; } } System.out.printf("%d,%d\n", point[0], point[1]); } }