题解 | #坐标移动#

坐标移动

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

import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);

        String[] temp=sc.nextLine().split(";");
        int x=0;
        int y=0;
        for(String s:temp){
            if(s.length()==0 || s.length()==1 || s.length()>3){
                continue;
            }
            switch (s.charAt(0)){
                case 'A':
                {
                    int num = 0;
                    int fla =0;
                    for(int i=1; i<s.length();i++){
                        if(s.charAt(i) > '9' || s.charAt(i) < 0){
                            fla = 1;
                            break;
                        }
                        num = num*10 + (s.charAt(i)-'0');
                    }
                    if(fla == 0){
                        x -= num;
                    }
                    break;
                }

                case 'D':
                {
                    int num = 0;
                    int fla =0;
                    for(int i=1; i<s.length();i++){
                        if(s.charAt(i) > '9' || s.charAt(i) < 0){
                            fla = 1;
                            break;
                        }
                        num = num*10 + (s.charAt(i)-'0');
                    }
                    if(fla == 0){
                        x += num;
                    }
                    break;
                }

                case 'W':
                {
                    int num = 0;
                    int fla =0;
                    for(int i=1; i<s.length();i++){
                        if(s.charAt(i) > '9' || s.charAt(i) < 0){
                            fla = 1;
                            break;
                        }
                        num = num*10 + (s.charAt(i)-'0');
                    }
                    if(fla == 0){
                        y += num;
                    }
                    break;
                }

                case 'S':
                {
                    int num = 0;
                    int fla =0;
                    for(int i=1; i<s.length();i++){
                        if(s.charAt(i) > '9' || s.charAt(i) < 0){
                            fla = 1;
                            break;
                        }
                        num = num*10 + (s.charAt(i)-'0');
                    }
                    if(fla == 0){
                        y -= num;
                    }
                    break;
                }

                default:
                    break;
            }
        }


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

    }
}

#哈啰出行招聘#
全部评论

相关推荐

11-09 11:01
济南大学 Java
Java抽象带篮子:外卖项目真得美化一下,可以看看我的详细的外卖话术帖子
点赞 评论 收藏
分享
去B座二楼砸水泥地:不过也可以理解,这种应该没参加过秋招
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务