题解 | #坐标移动#

坐标移动

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

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
       int x=0;
        int y=0;
        Scanner in=new Scanner(System.in);
        String pro=in.next();
        String[] ans=new String[pro.length()];
        String test="";
        int count=0;
        for (int i = 0; i <pro.length() ; i++) {
            if(pro.charAt(i)==';'){
                ans[count++]=test;
                test="";
            }
            else {
                test=test+pro.charAt(i);
            }
        }
        ans[count++]=test;
        for (int i = 0; i < count; i++) {
            if(ans[i].length()==3){
                if((ans[i].charAt(1)>=48&&ans[i].charAt(1)<=57)&&(ans[i].charAt(2)>=48&&ans[i].charAt(2)<=57)&&(ans[i].charAt(0)>=65&&ans[i].charAt(0)<=97)){
if(ans[i].charAt(0)=='A'){
    String c1="";
            c1=c1+ans[i].charAt(1)+ans[i].charAt(2);
            x=x-Integer.parseInt(c1);

}
else if(ans[i].charAt(0)=='W'){
    String c2="";
    c2=c2+ans[i].charAt(1)+ans[i].charAt(2);
    y=y+Integer.parseInt(c2);

}
else if(ans[i].charAt(0)=='D'){
    String c3="";
    c3=c3+ans[i].charAt(1)+ans[i].charAt(2);
    x=x+Integer.parseInt(c3);

}
else if(ans[i].charAt(0)=='S'){
    String c4="";
    c4=c4+ans[i].charAt(1)+ans[i].charAt(2);
    y=y-Integer.parseInt(c4);

}
                }

        }
            if(ans[i].length()==2){
                if((ans[i].charAt(1)>=48&&ans[i].charAt(1)<=57)&&(ans[i].charAt(0)>=65&&ans[i].charAt(0)<=97)){
                    if(ans[i].charAt(0)=='A'){
                        String c1="";
                        c1=c1+ans[i].charAt(1);
                        x=x-Integer.parseInt(c1);

                    }
                    else if(ans[i].charAt(0)=='W'){
                        String c2="";
                        c2=c2+ans[i].charAt(1);
                        y=y+Integer.parseInt(c2);

                    }
                    else if(ans[i].charAt(0)=='D'){
                        String c3="";
                        c3=c3+ans[i].charAt(1);
                        x=x+Integer.parseInt(c3);

                    }
                    else if(ans[i].charAt(0)=='S'){
                        String c4="";
                        c4=c4+ans[i].charAt(1);
                        y=y-Integer.parseInt(c4);

                    }
                }

            }


        }
        System.out.println(x+","+y);
    }
}

全部评论
新手,没想到自己这么蠢
点赞 回复 分享
发布于 2023-02-16 22:56 河南

相关推荐

05-28 23:26
河南大学 Java
双非本,刚学完Redis,项目只有外卖和点评,八股没准备,算法只有lqb省一,感觉敲的项目也是一言难尽没怎么吸收。怎么你们都有实习了
大牛之途:27急个锤子,你投日常实习最好的时间就是9,10月份,那时候暑期实习都结束了,正是缺人的时候。这份日常又能给你的暑期实习增加竞争力,暑期找的好了秋招也不怕了,都是环环相扣的
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务