fork download
  1. import java.util.*;
  2. import java.util.regex.*;
  3. import java.lang.*;
  4. import java.io.*;
  5. class Ideone
  6. {
  7. public static void main (String[] args) throws java.lang.Exception
  8. {
  9. Scanner sc = new Scanner(System.in);
  10. int n = sc.nextInt();
  11. sc.nextLine(); // Force it to consume the line break
  12. ArrayList<String> s = new ArrayList();
  13. for (int i = 0; i < n; i++)
  14. {
  15. String st = sc.nextLine();
  16. s.add(st);
  17. }
  18.  
  19. int q = sc.nextInt();
  20. sc.nextLine(); // Force it to consume the line break
  21. for (int i = 0; i < q; i++)
  22. {
  23. int count = 0;
  24. String st = sc.nextLine();
  25. String check = "\\B" + st + "\\B";
  26. Pattern p = Pattern.compile(check);
  27. for (int j = 0; j < n; j++)
  28. {
  29. Matcher m = p.matcher(s.get(j));
  30. while (m.find())
  31. {
  32. count += 1;
  33. }
  34. }
  35.  
  36. System.out.println(count);
  37. }
  38. }
  39. }
Success #stdin #stdout 0.09s 2841600KB
stdin
1
existing pessimist optimist this is
1
is
stdout
3