题解 | #坐标移动#java
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] str = reader.readLine().toUpperCase().split(";"); int j = 0, x = 0, y = 0, num = 0; for (int i = 0; i < str.length; i++) { if (str[i].length() > 1 && str[i].length() < 4) { if (str[i].charAt(0) == 'A' || str[i].charAt(0) == 'S' || str[i].charAt(0) == 'D' || str[i].charAt(0) == 'W') { if (Integer.valueOf(str[i].charAt(1)) > 47 && Integer.valueOf(str[i].charAt(1)) < 58) { if (str[i].length() != 2) { if (Integer.valueOf(str[i].charAt(2)) > 47 && Integer.valueOf(str[i].charAt(2)) < 58) { num = Integer.parseInt(str[i].substring(1)); switch (str[i].charAt(0)) { case 'A': x = x - num; break; case 'D': x = x + num; break; case 'S': y = y - num; break; case 'W': y = y + num; break; default: break; } } } else { num = Integer.parseInt(str[i].substring(1)); switch (str[i].charAt(0)) { case 'A': x = x - num; break; case 'D': x = x + num; break; case 'S': y = y - num; break; case 'W': y = y + num; break; default: break; } } } } } } System.out.println(x + "," + y); } }