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

  • 相关阅读:
    kafka 3.5 主题分区的高水位线HW,低水位线LW,logStartOffset,LogEndOffset什么情况下会更新源码
    春节活动 - 高峰值奖励发放技术方案
    地面监视雷达系统的设计与试验
    Python 采集87个手绘风格PPT模板
    OpenHarmony 持久化存储 UI 状态:PersistentStorage
    【Python基础入门8】关于字符串
    02-数组(Array)应用分析
    【译】.NET 7 中的性能改进(二)
    Docker 镜像的缓存特性
    springmvc拦截器与全局异常
  • 原文地址:https://blog.csdn.net/computer408/article/details/126281742