题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.Scanner;
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.next();
System.out.println(v(a));
}
}
//A10;S20;W10;D30;X;A1A;B10A11;;A10;
private static String v(String str) {
int x = 0;
int y = 0;
String[] step = str.split(";");
for (String s: step) {
try {
int value = Integer.parseInt(s.substring(1));
if (value <=0) continue;
if (s.startsWith("A")) {
x -= value;
}
if (s.startsWith("S")) {
y -= value;
}
if (s.startsWith("W")) {
y += value;
}
if (s.startsWith("D")) {
x += value;
}
} catch (Exception e) {
}
}
return x + "," + y;
}
}

