题解 | #统计一句话中重复单词的个数#

统计一句话中重复单词的个数

https://www.nowcoder.com/practice/2128e598b5a5407195c31175b5b33360

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();
        Map<Character, Integer> map = new LinkedHashMap<Character, Integer>();

        //write your code here......
        for (int i = 0; i < line.length(); i++) {
            char t = line.charAt(i);
            if (t >= 'a' && t <= 'z' || t >= 'A' && t <= 'Z') {
                if (map.containsKey(line.charAt(i))) {
                    map.put(t, map.get(t) + 1);
                } else {
                    map.put(t, 1);
                }
            }

        }


        Set<Map.Entry<Character, Integer>> entrys = map.entrySet();
        for (Map.Entry<Character, Integer> entry : entrys) {
            System.out.println(entry.getKey() + ":" + entry.getValue());
        }
    }
}

全部评论

相关推荐

老树开花:可以开始投了,不用等到觉得完全准备好。一边投一边根据面试反馈改简历是最高效的方式。简历上项目描述建议突出你解决的具体问题,比如编辑器的性能优化、大文档渲染怎么处理的,而不只是列技术栈。中厂前端实习现在竞争确实激烈,建议同时关注一些有AI业务的团队,前端加AI应用是很有差异化的组合。Vue全家桶基础扎实的话可以往SSR或者跨端方向延伸,这些是面试加分项。加油,时间还来得及。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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