题解 | #坐标移动#

坐标移动

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-27 10:46
点赞 评论 收藏
分享
10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
10-15 16:27
门头沟学院 C++
LeoMoon:建议问一下是不是你给他付钱😅😅
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务