fork download
  1. import java.io.IOException;
  2. import java.io.OutputStreamWriter;
  3. import java.util.Arrays;
  4. import java.io.BufferedWriter;
  5. import java.util.InputMismatchException;
  6. import java.io.OutputStream;
  7. import java.io.PrintWriter;
  8. import java.util.NoSuchElementException;
  9. import java.io.Writer;
  10. import java.math.BigInteger;
  11. import java.io.InputStream;
  12.  
  13. /**
  14.  * Built using CHelper plug-in
  15.  * Actual solution is at the top
  16.  */
  17. public class Main {
  18. public static void main(String[] args) {
  19. InputStream inputStream = System.in;
  20. OutputStream outputStream = System.out;
  21. InputReader in = new InputReader(inputStream);
  22. OutputWriter out = new OutputWriter(outputStream);
  23. PHONELST solver = new PHONELST();
  24. int testCount = Integer.parseInt(in.next());
  25. for (int i = 1; i <= testCount; i++)
  26. solver.solve(i, in, out);
  27. out.close();
  28. }
  29. }
  30.  
  31. class PHONELST {
  32. public void solve(int testNumber, InputReader in, OutputWriter out) {
  33. int n = in.readInt();
  34. String[] s = new String[n];
  35. for (int i = 0; i < n; i++) {
  36. s[i] = in.readString();
  37. }
  38. Arrays.sort(s);
  39. for (int i = 0; i < n - 1; i++) {
  40. if (s[i + 1].startsWith(s[i])) {
  41. out.printLine("NO");
  42. return;
  43. }
  44. }
  45. out.printLine("YES");
  46. }
  47. }
  48.  
  49.  
  50. class InputReader {
  51.  
  52. private InputStream stream;
  53. private byte[] buf = new byte[1024];
  54. private int curChar;
  55. private int numChars;
  56. private SpaceCharFilter filter;
  57.  
  58. public InputReader(InputStream stream) {
  59. this.stream = stream;
  60. }
  61.  
  62. public int read() {
  63. if (numChars == -1)
  64. throw new InputMismatchException();
  65. if (curChar >= numChars) {
  66. curChar = 0;
  67. try {
  68. numChars = stream.read(buf);
  69. } catch (IOException e) {
  70. throw new InputMismatchException();
  71. }
  72. if (numChars <= 0)
  73. return -1;
  74. }
  75. return buf[curChar++];
  76. }
  77.  
  78. public int readInt() {
  79. int c = read();
  80. while (isSpaceChar(c))
  81. c = read();
  82. int sgn = 1;
  83. if (c == '-') {
  84. sgn = -1;
  85. c = read();
  86. }
  87. int res = 0;
  88. do {
  89. if (c < '0' || c > '9')
  90. throw new InputMismatchException();
  91. res *= 10;
  92. res += c - '0';
  93. c = read();
  94. } while (!isSpaceChar(c));
  95. return res * sgn;
  96. }
  97.  
  98. public String readString() {
  99. int c = read();
  100. while (isSpaceChar(c))
  101. c = read();
  102. StringBuilder res = new StringBuilder();
  103. do {
  104. if (Character.isValidCodePoint(c))
  105. res.appendCodePoint(c);
  106. c = read();
  107. } while (!isSpaceChar(c));
  108. return res.toString();
  109. }
  110.  
  111. public boolean isSpaceChar(int c) {
  112. if (filter != null)
  113. return filter.isSpaceChar(c);
  114. return isWhitespace(c);
  115. }
  116.  
  117. public static boolean isWhitespace(int c) {
  118. return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  119. }
  120.  
  121. public String next() {
  122. return readString();
  123. }
  124.  
  125. public interface SpaceCharFilter {
  126. public boolean isSpaceChar(int ch);
  127. }
  128. }
  129.  
  130.  
  131. class OutputWriter {
  132. private final PrintWriter writer;
  133.  
  134. public OutputWriter(OutputStream outputStream) {
  135. writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
  136. }
  137.  
  138. public OutputWriter(Writer writer) {
  139. this.writer = new PrintWriter(writer);
  140. }
  141.  
  142. public void print(Object...objects) {
  143. for (int i = 0; i < objects.length; i++) {
  144. if (i != 0)
  145. writer.print(' ');
  146. writer.print(objects[i]);
  147. }
  148. }
  149.  
  150. public void printLine(Object...objects) {
  151. print(objects);
  152. writer.println();
  153. }
  154.  
  155. public void close() {
  156. writer.close();
  157. }
  158.  
  159. }
  160.  
  161.  
  162.  
Success #stdin #stdout 0.07s 380160KB
stdin
2
3
911
97625999
91125426
5
113
12340
123440
12345
98346
stdout
NO
YES