题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
Scanner in = new Scanner(System.in); String str = in.nextLine(); String []str1 = str.split(";"); int x=0; int y=0;
for(int i=0;i<str1.length;i++) {
boolean isnum=true;
if(str1[i].length()==0){
continue;
}
String flag = str1[i].substring(0, 1);
String temp = str1[i].substring(1,str1[i].length());
if(temp.length()==0){
continue;
}
//System.out.println(temp.length());
for(int j=0;j<temp.length();j++){
if(!Character.isDigit(temp.charAt(j))){
isnum = false;
break;
}
}
int num=0;
if(isnum){
num = Integer.parseInt(temp);
}else{
continue;
}
switch (flag) {
//A向左。D向右,S乡下,W向上
case "A": x=x-num;
break;
case "D": x=x+num;
break;
case "W": y=y+num;
break;
case "S": y=y-num;
break;
default:
break;
}
}
System.out.println(x+","+y);