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)