题解 | #坐标移动#
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
String[] a1 = a.split(";");
ArrayList<String> s1 = new ArrayList<>();
Set<Character> values = new HashSet<Character>(Arrays.asList('A','S','D','W'));
for(String s:a1){
char[] c = s.toCharArray();
if(c.length>=2 && c.length<=3 && values.contains(c[0]) && Character.isDigit(c[1]) && Character.isDigit(c[c.length-1]))
{
s1.add(s);
}
}
int n1 = 0;
int n2 = 0;
for(String s:s1){
int mv = Integer.parseInt(s.substring(1,s.length()));
String sub = s.substring(0,1);
if(sub.equals("A")){
n1 = n1-mv;
}
else if(sub.equals("W")){
n2 = n2+ mv;
}
else if(sub.equals("D")){
n1 += mv;
}
else{
n2 -= mv;
}
}
System.out.println(n1+","+n2);
}
}
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String a = sc.nextLine();
String[] a1 = a.split(";");
ArrayList<String> s1 = new ArrayList<>();
Set<Character> values = new HashSet<Character>(Arrays.asList('A','S','D','W'));
for(String s:a1){
char[] c = s.toCharArray();
if(c.length>=2 && c.length<=3 && values.contains(c[0]) && Character.isDigit(c[1]) && Character.isDigit(c[c.length-1]))
{
s1.add(s);
}
}
int n1 = 0;
int n2 = 0;
for(String s:s1){
int mv = Integer.parseInt(s.substring(1,s.length()));
String sub = s.substring(0,1);
if(sub.equals("A")){
n1 = n1-mv;
}
else if(sub.equals("W")){
n2 = n2+ mv;
}
else if(sub.equals("D")){
n1 += mv;
}
else{
n2 -= mv;
}
}
System.out.println(n1+","+n2);
}
}