题解 | #字符串归一化#

字符串归一化

https://www.nowcoder.com/practice/6d5e036defdf408681376a4a9d4930ff

HashTree红黑树搞定

import java.util.*;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()){
            String s=in.nextLine();
            solve(s);
        }
        
    }
    public static void solve(String s){
        char[] str = s.toCharArray();
        Map<Character,Integer> map  = new TreeMap<>();
        for(char i:str){
            if(!map.containsKey(i)){
                map.put(i,1);
            }else{
                int value = map.get(i);
                map.put(i,value+1);
            }
        }
        for(Map.Entry<Character,Integer> entry : map.entrySet()){
            System.out.print(entry.getKey());
            System.out.print(entry.getValue());
        }
    }
}

全部评论

相关推荐

01-11 08:47
门头沟学院 Java
choumoduji...:读研的目的就是为了以最快的速度和最低的要求完成“学校”规定的毕业标准,而不是所谓课题组的要求
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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