题解 | #坐标移动#
坐标移动
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 的区别 while (in.hasNext()) { // 注意 while 处理多个 case String a = in.nextLine(); if(a.length() <= 0 || a.length() > 10000){ //System.out.println("0,0"); } String[] arr = a.split(";"); int[][] aint = {{0,0}}; for(int i = 0; i < arr.length; i++){ String ar = arr[i]; if(!"".equals(ar.trim())){ String b = ar.substring(0,1); String c = ar.substring(1,ar.length()); try{ int d = Integer.valueOf(c); aint = updateArray(aint,b,d); }catch(Exception e){ //System.out.println("0,0"); } } } System.out.println(aint[0][0]+","+aint[0][1]); } } public static int[][] updateArray(int[][] a,String b, int c){ if("A".equals(b)){ a[0][0] = a[0][0] - c ; }else if("D".equals(b)){ a[0][0] = a[0][0] + c ; }else if("W".equals(b)){ a[0][1] = a[0][1] + c ; }else if("S".equals(b)){ a[0][1] = a[0][1] - c ; }else{ //System.out.println("0,0"); } return a; } }