题解 | #坐标移动#

坐标移动

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);
    }       
}

全部评论

相关推荐

求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
05-01 22:41
中南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务