题解 | #坐标移动#

坐标移动

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

全部评论

相关推荐

见见123:简历没有啥问题,是这个社会有问题。因为你刚毕业,没有工作经历,现在企业都不要没有工作经历的。社会病了。
点赞 评论 收藏
分享
流浪的神仙:无恶意,算法一般好像都得9硕才能干算法太卷啦
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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