Java解 | #HJ17坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner in = new Scanner(System.in); while(in.hasNext()){ int x=0,y=0; String[] arr = in.next().split(";"); for(int i=0;i<arr.length;i++){ if(arr[i].length() >= 2 && arr[i].length() <= 3 && arr[i].charAt(1) >= '0' && arr[i].charAt(1) <= '9'){ if(arr[i].length() == 2 || arr[i].length() == 3 && arr[i].charAt(2) >= '0' && arr[i].charAt(2) <= '9'){ if(arr[i].charAt(0) == 'A'){ x = x - Integer.parseInt(arr[i].substring(1)); } if(arr[i].charAt(0) == 'D'){ x = x + Integer.parseInt(arr[i].substring(1)); } if(arr[i].charAt(0) == 'W'){ y = y + Integer.parseInt(arr[i].substring(1)); } if(arr[i].charAt(0) == 'S'){ y = y - Integer.parseInt(arr[i].substring(1)); } } } } System.out.println(x + "," + y); } } }