题解 | #坐标移动#

坐标移动

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

正则表达式 HashMap

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        HashMap<String, Integer> map = new HashMap<>();
        while(scan.hasNext()){
            int x = 0;
            int y = 0;
            String str = scan.nextLine();
            String[] s = str.split(";");
            String res = "[WASD]\\d{1}\\d?";
            for(int i = 0; i<s.length; i++){
                if(s[i].matches(res)){
                    map.put(s[i].substring(0,1), map.getOrDefault(s[i].substring(0,1),0)+Integer.parseInt(s[i].substring(1)));
                }
            }
            x = map.get("D") - map.get("A");
            y = map.get("W") - map.get("S");
            System.out.println(x+","+y);
            map.clear();
        }
        scan.close();
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
今天 12:11
点赞 评论 收藏
分享
点赞 评论 收藏
分享
真烦好烦真烦:豆包润色了自己没看看吗,再说了,都说豆包是愚蠢且勤快的大学生,ds才是聪明的研究生,怎么敢让豆包写论文的
你们的毕业论文什么进度了
点赞 评论 收藏
分享
05-29 20:34
门头沟学院 C++
KarlAllen:得做好直接春招的准备。学历差的话,一是面试要求会比学历好的严格不少,二是就算面试通过了也会被排序。总之暑期和秋招对于学历差的就是及其不友好
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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