#坐标移动#一般解题思路

坐标移动

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int x = 0;
        int y = 0;
        String [] strs = in.nextLine().split(";");
        for( int i = 0;i < strs.length ;i ++){
            String str = strs[i];
            if(str != null && str.length() > 1){
                String tmpstr = str.substring(1);
                Integer tmp;
                try{
                    tmp = Integer.parseInt(tmpstr);
                }catch (Exception e){
                    tmp = null;
                }
                if(tmp != null ){
                     if(str.startsWith("A")){
                        x -= tmp;
                    }else if(str.startsWith("D")){
                        x += tmp;
                    }else if(str.startsWith("W")){
                        y += tmp;
                    }else if(str.startsWith("S")){
                        y -= tmp;
                    }
                }
               
            }
        }
        System.out.println(x + "," + y);
    }

    
}

全部评论

相关推荐

07-25 10:39
门头沟学院 Java
点赞 评论 收藏
分享
06-13 10:15
门头沟学院 Java
想去夏威夷的大西瓜在...:我也是27届,但是我现在研一下了啥项目都没有呀咋办,哎,简历不知道咋写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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