题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
正则表达式 HashMap
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
HashMap<String, Integer> map = new HashMap<>();
while(scan.hasNext()){
int x = 0;
int y = 0;
String str = scan.nextLine();
String[] s = str.split(";");
String res = "[WASD]\\d{1}\\d?";
for(int i = 0; i<s.length; i++){
if(s[i].matches(res)){
map.put(s[i].substring(0,1), map.getOrDefault(s[i].substring(0,1),0)+Integer.parseInt(s[i].substring(1)));
}
}
x = map.get("D") - map.get("A");
y = map.get("W") - map.get("S");
System.out.println(x+","+y);
map.clear();
}
scan.close();
}
}