题解 | #坐标移动#

坐标移动

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        String command = fzhinput.nextLine();
        String sqcommand[] = command.split(";");
        int i,j,jl,a=0,b=0;
        Character sjl;
        Boolean pd;
        StringBuilder stack = new StringBuilder();
        
        
        for(i=0;i<sqcommand.length;i++){
            pd=false;
            for(j=1;j<sqcommand[i].length();j++){
                    if(!Character.isDigit(sqcommand[i].charAt(j))){
                        pd=false;
                    }
                    else if(sqcommand[i].charAt(0)=='A'){
                        pd=true;
                    }
                    else if(sqcommand[i].charAt(0)=='D'){
                        pd=true;
                    }
                    else if(sqcommand[i].charAt(0)=='W'){
                        pd=true;
                    }
                    else if(sqcommand[i].charAt(0)=='S'){
                        pd=true;
                    }
                    else{

                    }
                    
                }
            if(!pd){

            }
            else if(pd && sqcommand[i].charAt(0)=='A'){
                for(j=1;j<sqcommand[i].length();j++){
                    sjl = sqcommand[i].charAt(j);
                    stack.append(sjl);
                }
                jl = Integer.parseInt(stack.toString());
                a=a-jl;
                stack.setLength(0);
            }
            else if(pd && sqcommand[i].charAt(0)=='D'){
                for(j=1;j<sqcommand[i].length();j++){
                    sjl = sqcommand[i].charAt(j);
                    stack.append(sjl);
                }
                jl = Integer.parseInt(stack.toString());
                a=a+jl;
                stack.setLength(0);
            }
            else if(pd && sqcommand[i].charAt(0)=='W'){
                for(j=1;j<sqcommand[i].length();j++){
                    sjl = sqcommand[i].charAt(j);
                    stack.append(sjl);
                }
                jl = Integer.parseInt(stack.toString());
                b=b+jl;
                stack.setLength(0);
            }
            else if(pd && sqcommand[i].charAt(0)=='S'){
                for(j=1;j<sqcommand[i].length();j++){
                    sjl = sqcommand[i].charAt(j);
                    stack.append(sjl);
                }
                jl = Integer.parseInt(stack.toString());
                b=b-jl;
                stack.setLength(0);
            }
        }
        System.out.println(a+","+b);
    }
}

全部评论

相关推荐

贺兰星辰:不要漏个人信息,除了简历模板不太好以外你这个个人简介是不是太夸大了...
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务