题解 | #坐标移动#

坐标移动

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String input = scan.nextLine();
        String[] steps = input.split(";");
        int[] location = new int[2];
        for (int i = 0; i < steps.length; i++) {
            if(steps[i].length() < 2){
                continue;
            }
            for(int j = 1; j < steps[i].length(); j++){
                char c = steps[i].charAt(j);
                if(c < '0' || c > '9'){
                    i++;
                    break;
                }
            }
            if(i == steps.length){
                break;
            }
            char direction = steps[i].charAt(0);
            if(steps[i].charAt(0) == 'A'){
                location[0] -= Integer.parseInt(steps[i].substring(1));
            }else if(steps[i].charAt(0) == 'D'){
                location[0] += Integer.parseInt(steps[i].substring(1));
            }else if(steps[i].charAt(0) == 'W'){
                location[1] += Integer.parseInt(steps[i].substring(1));
            }else if(steps[i].charAt(0) == 'S'){
                location[1] -= Integer.parseInt(steps[i].substring(1));
            }
        }
       System.out.print(location[0] + "," + location[1]);
    }
}

全部评论

相关推荐

榕城小榕树:1200单休,我去干点啥别的不好
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-04 14:35
点赞 评论 收藏
分享
半解316:内容充实,细节需要修改一下。 1,整体压缩为一页。所有内容顶格。 2,项目描述删除,直接写个人工作量 修改完之后还需要建议,可以私聊
点赞 评论 收藏
分享
仁者伍敌:牛子这些人还会点一个自动回复,boss都不带回复的
点赞 评论 收藏
分享
面向对象的火龙果很爱...:去吃一顿炸鸡就走
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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