• HJ17 坐标移动----牛客刷题


    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.*;


    public class Step1 {
        
        static List chs=new ArrayList();
        static int x,y=0;
        public static void main(String[] args) throws IOException {
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                String str=reader.readLine();
                chs.add('A');
                chs.add('D');
                chs.add('S');
                chs.add('W');
                //ADSW  0-99
                //分离成数组,判断第一个字母所属,判断除第一个字母外是否为数字
                //考虑分离基础   
                String[] strs=str.split(";");
                for (int i = 0; i < strs.length; i++) {
                    if(strs[i].length()>=1){
                        jude(strs[i]);
                    }
                }
                System.out.println(x+","+y);
                
         }
         public static void jude(String str){
             if(Step1.chs.contains(str.charAt(0))){
                 switch(str.charAt(0)){
                 case 'W':
                     y+= format(str);
                     break;
                 case 'S':
                     y-= format(str);
                     break;
                 case 'A':
                     x-= format(str);
                     break;
                 case 'D':
                     x+=format(str);
                     break;
                 }
             }
         }
         public static int format(String str){
            try{
                int val = Integer.valueOf(str.substring(1));//异常点,数字转换异常
                return val;
            }catch (Exception e) {
                
            }
            return 0;
         }
    }
     

  • 相关阅读:
    11.11 校招 实习 内推 面经
    单值二叉树
    Python 全栈系列195 Neo4j 4.4 Docker安装
    Spring 6【方法参数校验、SpingAOP介绍、Schema-based方式实现AOP 】(十四)-全面详解(学习总结---从入门到深化)
    C++基础入门
    MySQL事务管理
    KNN聚类算法
    2.3_9吸烟者问题
    Allegro的引流方式有哪些?Allegro买家号测评提高店铺的权重和排名
    shell_56.Linux永久重定向
  • 原文地址:https://blog.csdn.net/computer408/article/details/126281742