题解 | #坐标移动#
坐标移动
http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
public class Main { public static void main(String[] args) { java.util.Scanner sc = new java.util.Scanner(System.in); String[] str = sc.nextLine().split(";"); int x =0; int y =0; int z =0; for(int i = 0;i<str.length;i++){ if(str[i].length()<=3){ if(str[i].startsWith("A")){ try{ z = Integer.valueOf(str[i].substring(1,str[i].length())); x =x - z; }catch (Exception e){ } } if(str[i].startsWith("D")){ try{ z = Integer.valueOf(str[i].substring(1,str[i].length())); x =x + z; }catch (Exception e){ } } if(str[i].startsWith("W")){ try{ z = Integer.valueOf(str[i].substring(1,str[i].length())); y =y + z; }catch (Exception e){ } } if(str[i].startsWith("S")){ try{ z = Integer.valueOf(str[i].substring(1,str[i].length())); y =y - z; }catch (Exception e){ } } } } System.out.println(x+","+y); } }