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"