Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Iterator;
- import java.util.List;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Searcher {
- public static void main(String[] args) {
- String[] as = {"A", "B", "C", "D", "E"};
- List<String> ls = new ArrayList<String>();
- ls.addAll(Arrays.asList(as));
- System.out.println(ls);
- Scanner in = null;
- try {
- in = new Scanner(System.in);
- }
- catch (Exception e) {
- }
- List<String> qs = new ArrayList<String>();
- while (in.hasNextLine())
- qs.add(Pattern.quote(in.nextLine().trim()));
- StringBuilder sb = new StringBuilder();
- sb.append("(");
- Iterator<String> it = qs.iterator();
- while (it.hasNext()) {
- sb.append(it.next());
- if (it.hasNext()) sb.append("|");
- }
- sb.append(")");
- Pattern query = Pattern.compile(sb.toString());
- int find = 0;
- for (String s: ls) {
- Matcher m = query.matcher(s);
- if(m.find()) {
- find++;
- System.out.println(s);
- }
- }
- System.out.println((double)find / ls.size());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement