题解 | #坐标移动#

坐标移动

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

不知道为啥自测通过不了 但提交可以运行

import java.util.*;
public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        String move[]=sc.nextLine().split(";");
        int axisx=0;
        int axisy=0;
        String offset=new String();
        for (int i=0;i<move.length;i++){
            offset=move[i].substring(1);
            if(offset.matches("[0-9]+")){
                if(move[i].charAt(0)=='A'){
                   axisx-=Integer.parseInt(offset);
                }
                if(move[i].charAt(0)=='S'){
                    axisy-=Integer.parseInt(offset);
                }
                if(move[i].charAt(0)=='W'){
                    axisy+=Integer.parseInt(offset);
                }
                if(move[i].charAt(0)=='D'){
                    axisx+=Integer.parseInt(offset);
                }
        }
        }
        System.out.println(axisx+","+axisy);

    }
}
全部评论

相关推荐

点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务