"Phone number sort--Simple qsort function"

Source: Internet
Author: User
Tags strcmp

Phone List

Time Limit:2 Sec Memory limit:64 MB submit:359 solved:79 [Submit][status][discuss]

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:

-Emergency 911-alice 625 999-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 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
HINT

zoj2876

Source

The Nordic Collegiate Programming Contest

Note: qsort function format:int CMP (ConstVoid* A,Constvoid*b
{
return strcmp ((char*) A, ( char*                                    }
                                      int Main ()

                                     {  

                                                 qsort (A,n,sizeof (A[0

}

#include <stdio.h>#include<string.h>#include<stdlib.h>intcmpConst voidBConst void*b) {    returnstrcmp ((Char*) A, (Char*) b);}intMain () {intT,n,i,temp,j,len; Chara[10000][ -],str[ -]; scanf ("%d",&t);  while(t--) {scanf ("%d",&n); GetChar (); Temp=0;  for(i=0; i<n;i++) {gets (a[i]); } qsort (A,n,sizeof(a[0]), CMP);  for(i=0; i<n-1; i++)        {            if(STRNCMP (a[i],a[i+1],strlen (a[i]) = =0) {Temp=1;  Break; }        }        if(temp==0) printf ("yes\n"); Elseprintf ("no\n"); }    return 0;
}

  

  

"Phone number sort--Simple qsort function"

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.