题解 | #坐标移动#

坐标移动

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

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static Map<String, Integer> map = new HashMap<String, Integer>() {
        {
            put("A", -1);
            put("D", 1);
            put("W", 1);
            put("S", -1);
        }
    };
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        String arrays[] = str.split(";");
        int[] res = new int[2];
        boolean x = true;
        for (String s : arrays) {
            if (s.length() >= 2 && s.length() <= 3) {
                String ch = s.substring(0, 1);
                String n = s.substring(1);
                if (map.containsKey(ch)) {
                    if ("A".equals(ch) || "D".equals(ch)) {
                        x = true;
                    } else {
                        x = false;
                    }
                    if (n.matches("\\d+")) {
                        int num = Integer.valueOf(n);
                        if (x) {
                            res[0] = res[0] + num * map.get(ch);
                        } else {
                            res[1] = res[1] + num * map.get(ch);
                        }
                    }
                }
            }
        }
        System.out.println(res[0] + "," + res[1]);
    }
}

全部评论

相关推荐

神哥不得了:首先我就是在成都,成都的互联网格外的卷,如果是凭现在的简历的话很难找到大厂,建议再添加一个高质量的项目上去,另外专业技能的话最好是超过每一条的一半
点赞 评论 收藏
分享
虚闻松声:很顶的简历,不改也没啥问题。 两点建议 1. 细化项目经历。关于【负责内容】可以稍微再具体一些,重点项目可以写两三个大的模块,以列表形式展开。同时适当提一下项目最终的效果。 2. 适当精炼表达。课程写一行足矣;荣誉奖项,写成一两行吧;CET-6再加一句话就行了,4 没必要写 CV、求职等咨询,欢迎私信交流。
投递中科院自动化所等公司9个岗位 > 听劝,这个简历怎么改
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务