import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Test55 {
/*
题目描述
开发一个坐标计算工具, A表示向左移动,D表示向右移动,W表示
向上移动,S表示向下移动。从(0,0)点开始移动,从输入字符串
里面读取一些坐标,并将最终输入结果输出到输出文件里面。
输入:
合法坐标为A(或者D或者W或者S) + 数字(两位以内)
坐标之间以;分隔。
非法坐标点需要进行丢弃。如AA10; A1A; $%$; YAD; 等。
下面是一个简单的例子 如:
A10;S20;W10;D30;X;A1A;B10A11;;A10;
处理过程:
起点(0,0)
+ A10 = (-10,0)
+ S20 = (-10,-20)
+ W10 = (-10,-10)
+ D30 = (20,-10)
+ x = 无效
+ A1A = 无效
+ B10A11 = 无效
+ 一个空 不影响
+ A10 = (10,-10)
结果 (10, -10)
输入描述:
一行字符串
输出描述:
最终坐标,以,分隔
输入例子:
A10;S20;W10;D30;X;A1A;B10A11;;A10;
输出例子:
10,-10
*/
public static void main(String[] args) {
Scanner scn=new Scanner(System.in);
while(scn.hasNext()){
getResult(scn.nextLine());
}
}
public static void getResult(String str){
Map<Integer, String> map=new HashMap<Integer, String>();
int x=0;
int y=0;
String[] strs=str.split(";");
for (int i = 0; i < strs.length; i++) {
if(isRight(strs[i])){
for (Entry<Integer, Integer> e:getZouBu(strs[i], x, y).entrySet()) {
x=e.getKey();
y=e.getValue();
}
//System.out.println("("+x+","+y+")");
}
}
System.out.println(x+","+y);
}
public static Map<Integer, Integer>getZouBu(String str,int x,int y){
Map<Integer, Integer> map=new HashMap<Integer, Integer>();
if(str.charAt(0)=='A'){
x=x-Integer.parseInt(str.substring(1));
}
if(str.charAt(0)=='D'){
x=x+Integer.parseInt(str.substring(1));
}
if(str.charAt(0)=='W'){
y=y+Integer.parseInt(str.substring(1));
}
if(str.charAt(0)=='S'){
y=y-Integer.parseInt(str.substring(1));
}
map.put(x,y);
return map;
}
public static boolean isRight(String str){
String str0="ASDW";
String str1="0123456789";
if(str.length()==2
&&str0.contains(""+str.charAt(0))
&&str1.contains(""+str.charAt(1))){
return true;
}
if(str.length()==3
&&str0.contains(""+str.charAt(0))
&&str1.contains(""+str.charAt(1))
&&str1.contains(""+str.charAt(2))){
return true;
}
return false;
}
}