# E-phone List (dictionary order, string type used)

Source: Internet
Author: User

Description

Given a list of phone numbers, determine if it is consistent in the sense this no number is the prefix of another. Let ' s say the phone catalogue listed these numbers:
1. Emergency 911
2. Alice 97 625 999
3. Bob 91 12 54 26
In this case, it's not possible-to-call Bob, because-the central would direct your-to-the-emergency line as soon as Y OU had dialled the first three digits of Bob ' s phone number. So the list would not being consistent.

Input

The first line of input gives a single integer, 1 <= t <=, the number of test cases. Each test case is starts with N, the number of the phone numbers, on a separate line, 1 <= n <= 10000. Then follows n lines with a unique phone number on each line. A phone number is a sequence of at the most ten digits.

Output

For each test case, the output "YES" If the list is consistent, or "NO" otherwise.

Sample Input

2391197625999911254265113123401234401234598346

Sample Output

NOYES source:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=91073#problem/e The title means that no number in the input number is the prefix of another number: all numbers are sorted by dictionary order, (sort functions can be sorted by dictionary), and then all numbers are traversed to see if the previous number is the prefix code for the latter number.
`#include <stdio.h>#include<string>#include<iostream>#include<algorithm>using namespacestd;strings[10010];BOOLJudgeintN) {    intLen, I, J;  for(i =0; I < n1; i++) {len=s[i].size (); //printf ("\n%d\n", Len);         for(j =0; J < Len; J + +)        {            if(S[i][j]! = s[i+1][j]) {//cout << s[i][j] << ' << s[i+1][j];                 Break; }        }        //printf ("\n%d\n", j);        if(J = =len)return true; }    return false;}intMain () {intT; scanf ("%d", &t);  while(t--)    {        intN; scanf ("%d", &N);  for(inti =0; I < n; i++) Cin>>S[i]; Sort (s, S+N); //for (int i = 0; i < n; i++)//cout << s[i] << "";        if(judge (n)) printf ("no\n"); Elseprintf ("yes\n"); }    return 0;}`

E-phone List (dictionary order, string type used)

Related Keywords:

### Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.