fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone {
  9. final static char HIGHEST_CHAR = 'z'; // Use Character.MAX_VALUE if unsure.
  10.  
  11. public static void main(final String[] args) {
  12. final Scanner scanner = new Scanner(System.in);
  13. final boolean[] characterSeen = new boolean[HIGHEST_CHAR + 1];
  14.  
  15. mainloop:
  16. for (int word = Integer.parseInt(scanner.nextLine()); word > 0; word--) {
  17. Arrays.fill(characterSeen, false);
  18.  
  19. final String word1 = scanner.nextLine();
  20. for (int i = 0; i < word1.length(); i++) {
  21. characterSeen[word1.charAt(i)] = true;
  22. }
  23.  
  24. final String word2 = scanner.nextLine();
  25. for (int i = 0; i < word2.length(); i++) {
  26. if (characterSeen[word2.charAt(i)]) {
  27. System.out.println("YES");
  28. continue mainloop;
  29. }
  30. }
  31.  
  32. System.out.println("NO");
  33. }
  34. }
  35. }
Success #stdin #stdout 0.06s 2184192KB
stdin
2
abc
def
abc
cde
stdout
NO
YES