题解 | #坐标移动#

坐标移动

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 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String a = in.nextLine();
            if(a.length() <= 0 || a.length() > 10000){
                //System.out.println("0,0");
            }
            String[] arr  = a.split(";");
            int[][] aint = {{0,0}};
            for(int i = 0; i < arr.length; i++){
                String ar = arr[i];
                if(!"".equals(ar.trim())){
                    String b = ar.substring(0,1);
                    String c = ar.substring(1,ar.length());
                    try{
                        int d = Integer.valueOf(c);
                        aint = updateArray(aint,b,d);
                    }catch(Exception e){
                        //System.out.println("0,0");
                    }
                }
            }
            System.out.println(aint[0][0]+","+aint[0][1]);
        }
    }

    public static int[][] updateArray(int[][] a,String  b, int c){
        if("A".equals(b)){
            a[0][0] = a[0][0] - c ;
        }else if("D".equals(b)){
            a[0][0] = a[0][0] + c ;
        }else if("W".equals(b)){
            a[0][1] = a[0][1] + c ;
        }else if("S".equals(b)){
            a[0][1] = a[0][1] - c ;
        }else{
            //System.out.println("0,0");
        }
        return a;
    }
}

全部评论

相关推荐

07-02 13:52
门头沟学院 Java
点赞 评论 收藏
分享
兄弟们,实习都是在接各种api,该怎么包装简历
仁者伍敌:感觉我自己做小项目也是各种api啊,我要怎么包装简历
点赞 评论 收藏
分享
机械打工仔:我来告诉你原因,是因为sobb有在线简历,有些HR为了快会直接先看在线简历,初步感觉不合适就不会找你要详细的了
投了多少份简历才上岸
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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