-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExam_00.java
More file actions
55 lines (49 loc) · 1.27 KB
/
Exam_00.java
File metadata and controls
55 lines (49 loc) · 1.27 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
49
50
51
52
53
54
55
import java.io.FileInputStream;
import java.util.*;
public class Exam_00 {
/**
* @param args
*/
static int N, Answer;
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
System.setIn(new FileInputStream("src/data/exam00.txt"));
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int tc = 0; tc < T; tc++) {
int L = sc.nextInt();
int P = sc.nextInt();
String input = sc.next();
//System.out.println(input);
List li = new ArrayList();
TreeSet<String> ts = new TreeSet<String>();
for (int i = 0; i < input.length(); i++) {
if(i+P < L) {
li.add(input.substring(i, i+P));
ts.add((String) input.substring(i, i+P));
}
}
List<String> li2 = new ArrayList<String>(ts);
Answer = 0;
int cnt;
int max = 0;
for (int i = 0; i < li2.size(); i++) {
cnt = 0;
for (int j = 0; j < li.size(); j++) {
//System.out.println(li2.get(i) + " : " + li.get(j));
if(li2.get(i).equals(li.get(j))) {
cnt++;
if(max < cnt) {
max = cnt;
}
}
}
if(cnt >= 2) {
Answer = max;
//System.out.println(max);
}
}
System.out.println("# " + (tc+1) + " " + Answer);
}
}
}