-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString_23.java
More file actions
40 lines (31 loc) · 957 Bytes
/
Copy pathString_23.java
File metadata and controls
40 lines (31 loc) · 957 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package HuaweiCoding;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map.Entry;
public class String_23 {
public static String CovertToNewOne(String inputStr) {
TreeMap<Character, Integer> treeMap=new TreeMap<>();
for(int i=0;i<inputStr.length();i++) {
if(treeMap.containsKey(inputStr.charAt(i))) {
treeMap.put(inputStr.charAt(i), treeMap.get(inputStr.charAt(i))+1);
}else {
treeMap.put(inputStr.charAt(i), 1);
}
}
StringBuilder sb=new StringBuilder();
for (Entry<Character, Integer> keyValue : treeMap.entrySet()) {
int counts=keyValue.getValue();
for(int i=0;i<counts;i++) {
sb.append(keyValue.getKey());
}
}
return sb.toString();
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
String inputStr = sc.nextLine();
System.out.println(CovertToNewOne(inputStr));
}
}
}