题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.Scanner;
public class Main { public static void main(String[] args) { int x = 0; int y = 0; Scanner in = new Scanner(System.in); String str = ""; // 注意 hasNext 和 hasNextLine 的区别 while (in.hasNextLine()) { // 注意 while 处理多个 case
str += in.nextLine();
System.out.println(str);
}
String arr[] = str.split(";");
for (String s : arr) {
if (s.length() <= 3 && s.length() >= 2) {
char c = s.charAt(0);
int xx = 0;
int yy = 0;
if (c == 'A' || c == 'S' || c == 'W' || c == 'D') {
if (s.length() == 3) {
if (s.charAt(1) >= '0' && s.charAt(1) <= '9' && s.charAt(2) >= '0' && s.charAt(2) <= '9') {
int aa = Integer.valueOf("" + s.charAt(1) + s.charAt(2));
if (c == 'A') {
xx = -1 * aa;
yy = 0;
} else if (c == 'S') {
xx = 0;
yy = -1 * aa;
} else if (c == 'W') {
xx = 0;
yy = aa;
} else if (c == 'D') {
xx = aa;
yy = 0;
}
}
}
if (s.length() == 2) {
if (s.charAt(1) >= '0' && s.charAt(1) <= '9') {
int aa = Integer.valueOf("" + s.charAt(1));
if (c == 'A') {
xx = -1 * aa;
yy = 0;
} else if (c == 'S') {
xx = 0;
yy = -1 * aa;
} else if (c == 'W') {
xx = 0;
yy = aa;
} else if (c == 'D') {
xx = aa;
yy = 0;
}
}
}
}
x = x+xx;
y = y+yy;
}
}
System.out.println(x+","+y);
}
}