Java解 | #HJ17坐标移动#

坐标移动

http://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int x=0,y=0;
            String[] arr = in.next().split(";");
            for(int i=0;i<arr.length;i++){
                if(arr[i].length() >= 2 && arr[i].length() <= 3 && arr[i].charAt(1) >= '0' && arr[i].charAt(1) <= '9'){
                    if(arr[i].length() == 2 || arr[i].length() == 3 && arr[i].charAt(2) >= '0' && arr[i].charAt(2) <= '9'){
                        if(arr[i].charAt(0) == 'A'){
                            x = x - Integer.parseInt(arr[i].substring(1));
                        }
                        if(arr[i].charAt(0) == 'D'){
                            x = x + Integer.parseInt(arr[i].substring(1));
                        }
                        if(arr[i].charAt(0) == 'W'){
                            y = y + Integer.parseInt(arr[i].substring(1));
                        }
                        if(arr[i].charAt(0) == 'S'){
                            y = y - Integer.parseInt(arr[i].substring(1));
                        }
                    }
                }
            }
            System.out.println(x + "," + y);
        }
    }
}
全部评论

相关推荐

评论
1
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务