public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
String temp[] = str.split(";");
int x = 0, y = 0;
String res = "[AWSD]\\d{1,2}";//正则表达式
for (String s : temp) {
if (s.matches(res)) {
char ch = s.charAt(0);
int distance = Integer.valueOf(s.substring(1));
switch (ch) {
case 'A':
x -= distance;
break;
case 'D':
x += distance;
break;
case 'W':
y += distance;
break;
case 'S':
y -= distance;
break;
}
}
}
System.out.println(x + "," + y);
}
OJ---坐标移动
最新推荐文章于 2025-05-24 10:42:46 发布