-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinStr.java
More file actions
35 lines (32 loc) · 971 Bytes
/
MinStr.java
File metadata and controls
35 lines (32 loc) · 971 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
package com.hw;
import java.util.*;
/**
* @author: yhl
* @DateTime: 2020/5/15 13:15
* @Description:
*/
public class MinStr {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNextLine()) {
Map<Character, Integer> map = new IdentityHashMap<>();
char[] ch = in.nextLine().toCharArray();
for (char c : ch) {
if (map.containsKey(c)) {
map.put(c, map.get(c) + 1);
} else {
map.put(c, 1);
}
}
final Collection<Integer> values = map.values();
final Integer min = Collections.min(values);
StringBuilder sb = new StringBuilder();
for (char c : ch) {
if (!map.get(c).equals(min)) {
sb.append(c);
}
}
System.out.println(sb.toString());
}
}
}