-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJ03031.java
More file actions
48 lines (44 loc) · 1.25 KB
/
J03031.java
File metadata and controls
48 lines (44 loc) · 1.25 KB
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
41
42
43
44
45
46
47
48
import java.util.*;
import java.math.*;
public class J03031 {
public static boolean check(String s, int n) {
if (s.length() < n) {
return false;
}
HashMap<Character, Integer> mp = new HashMap<>();
for (Character x : s.toCharArray()) {
if (mp.containsKey(x)) {
mp.put(x, mp.get(x) + 1);
} else {
mp.put(x, 1);
}
}
int du = 0;
int size = mp.size();
Set<Map.Entry<Character, Integer>> et = mp.entrySet();
for (Map.Entry<Character, Integer> x : et) {
du += x.getValue();
}
int kq = Math.min(n,du);
if (size + kq >= 26) {
return true;
} else {
return false;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
sc.nextLine();
while (t-- > 0) {
String s = sc.nextLine();
int n = sc.nextInt();
sc.nextLine();
if (check(s, n)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}
}
}