题解 | #坐标移动#
坐标移动
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); // 注意 hasNext 和 hasNextLine 的区别 int X =0,Y =0; while (in.hasNext()) { // 注意 while 处理多个 case String a = in.nextLine(); String[] arr = a.split(";"); for(int i =0;i < arr.length;i++ ){ if(arr[i].length()>3 || arr[i].length()<2){ continue; } int s = 0; try{s = Integer.parseInt(arr[i].substring(1));} catch( Exception e ){ continue; } switch (arr[i].charAt(0)){ case 'A' : X -=s; break; case 'D' : X +=s; break; case 'W': Y +=s; break; case 'S': Y -=s; break; } } String res = X +","+Y; System.out.println(res); } } }