题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
最最最基础的方法,需要考虑条件太多,思路简单,但是不如学学别人的方法
public class Main{
public static void main(String [] args){
Scanner sc = new Scanner(System.in);
String [] str = sc.nextLine().split(";");
int a = 0;
int b = 0;
int op = 0;
for(String s : str){
if( s == null || s.trim().length() == 0) continue;
char c0 = s.charAt(0);
if(s.length()==3||s.length()==2) {
if(c0=='A'||c0=='D'||c0=='W'||c0=='S') {
char c1 = s.charAt(1);
if(s.length()==3){
char c2 = s.charAt(2);
int x = 0, y = 0;
x = c1 - '0';
y = c2 - '0';
if(x>0&&x<=9&&y>=0&&y<=9){
if(c0=='A'){a -= (10*x+y);}
else if(c0=='S'){ b -= (10*x+y);}
else if(c0=='D'){ a += 10*x+y;}
else if(c0=='W'){ b += 10*x+y;}
}
}
else if(s.length()==2){
int x = 0;
x = c1 - '0';
if(x>0&&x<=9){
if(c0=='A'){a -= x;}
else if(c0=='S'){ b -= x;}
else if(c0=='D'){ a += x;}
else if(c0=='W'){ b += x;}
}
}
}
}
}
System.out.println(a+","+b);
}
}