import java.util.HashMap; import java.util.Scanner; /** * 坐标移动(字符串)华为 * A左,D右,W上,S下(从0,0开始) * */ public class Main { public static void main(String[] args) { String str = new Scanner(System.in).nextLine(); //正则匹配坐标的字符串规则 String patten = "^[ADWS]\\d{1,2}$"; String[] strings = str.split(";"); int coordinateLeft = 0; int coordinateRight = 0; //使用map统计上下左右移动的总情况 HashMap<Character, Integer> map = new HashMap<>(); for (String string : strings) { if (string.matches(patten)){//如果匹配就进行坐标的更新 map.put(string.charAt(0),map.getOrDefault(string.charAt(0),0) + Integer.parseInt(string.substring(1))); } }//结束后,统计出ASWD的总情况 //进行计算(AD一对,WS一对) coordinateLeft = coordinateLeft - map.get('A') + map.get('D'); coordinateRight = coordinateRight + map.get('W') - map.get('S'); System.out.println(coordinateLeft + "," + coordinateRight); } }