-
Notifications
You must be signed in to change notification settings - Fork 19
/
cargame.java
43 lines (34 loc) · 868 Bytes
/
cargame.java
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
import java.util.ArrayList;
public class cargame {
public static void main(String[] args) {
Kattio scan = new Kattio(System.in);
int M = scan.getInt();
int N = scan.getInt();
ArrayList<String> dictionary = new ArrayList<>(M);
for (int i = 0; i < M; i++)
dictionary.add(scan.getWord());
for (int i = 0; i < N; i++)
{
String str = scan.getWord().toLowerCase();
char a = str.charAt(0);
char b = str.charAt(1);
char c = str.charAt(2);
boolean valid = false;
for (int x = 0; x < dictionary.size(); x++)
{
String check = dictionary.get(x);
int occ1 = check.indexOf(a);
int occ2 = check.indexOf(b , occ1 + 1);
int occ3 = check.indexOf(c , occ2 + 1);
if (occ1 == -1 || occ2 == -1 || occ3 == -1)
continue;
System.out.println(check);
valid = true;
break;
}
if (!valid)
System.out.println("No valid word");
}
scan.close();
}
}