题解 | #坐标移动#

坐标移动

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

全部评论

相关推荐

昨天 17:42
门头沟学院 Java
点赞 评论 收藏
分享
09-21 21:14
门头沟学院
否极泰来来来来:和他说:这里不好骂你,我们加个微信聊
点赞 评论 收藏
分享
牛客41406533...:回答他在课上学,一辈子待在学校的老教授用三十年前的祖传PPT一字一句的讲解,使用谭浩强红皮书作为教材在devc++里面敲出a+++++a的瞬间爆出114514个编译错误来学这样才显得专业
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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