-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlphabetSoup.java
More file actions
46 lines (35 loc) · 1.27 KB
/
AlphabetSoup.java
File metadata and controls
46 lines (35 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
//2006 - #2
import java.util.*;
public class AlphabetSoup {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Scanner inputString = new Scanner(System.in);
int times = input.nextInt();
for(int i = 0; i < times; i++){
String in = inputString.nextLine();
int messages = input.nextInt();
for(int x = 0; x < messages; x++){
ArrayList<String> letters = new ArrayList<String>();
for(int c = 0; c < in.length(); c++){
letters.add(in.substring(c,c + 1).toLowerCase());
}
boolean valid = true;
String test = inputString.nextLine();
for(int j = 0; j < test.length(); j++){
if(!letters.contains(test.substring(j,j + 1).toLowerCase()) && Character.isLetter(test.charAt(j))){
valid = false;
} else if (Character.isLetter(test.charAt(j))) {
letters.remove(letters.indexOf(test.substring(j,j + 1).toLowerCase()));
}
}
if(valid){
System.out.println(test + " : YES");
} else {
System.out.println(test + " : NO");
}
}
System.out.println();//As per requirments
inputString.nextLine();
}
}
}