The topic describes the mobile launch of the Xiaonei Cornet and family network Cornet is very convenient, but in a new phone but there is an embarrassing bug. For example, when the following number is included in the Address book:
1. Xiao Wang: 600
2. Xiao Li: 467654
3. Xiao Zhang: 600010
When you enter 600, the phone will automatically call the king, so you will never be able to call Xiao Zhang. Now, there are a lot of phones that have this problem,<span>nowcoder</span> want to find a way to judge whether the numbers in each number book are in this conflict. Input Description:
Enter more than one set of data.
The first row of each set of data is an integer n, (1≤n≤10000).
Immediately followed by n-line phone numbers, the number is only a number, the length of not more than 11.
Output Description:
One row for each set of inputs: if there are conflicting numbers in the phone book, output "Yes", otherwise output "No".
Example 1 input replication
3
911
97625999
91125426
5
113
12340
123440
12345
98346
Output replication
Yes
No
The code is as follows:
1 PackageCom.yzh.xuexi;2 3 Importjava.util.Arrays;4 ImportJava.util.Scanner;5 6 Public classConflictphonenumber {7 8 Public Static voidMain (string[] args) {9Scanner Scanner =NewScanner (system.in);Ten while(Scanner.hasnext ()) { One intn=integer.valueof (Scanner.nextline ()); AString[] Arr=NewString[n]; - for(inti = 0; i < arr.length; i++) { -arr[i]=scanner.nextline (); the } - System.out.println (Conflictphonenumber (arr)); - } - scanner.close (); + - } + A //Can also be solved using a dictionary tree at Private StaticString conflictphonenumber (string[] arr) { -Arrays.sort (arr);//use the arrays built-in sort () function to sort the strings by default rules from small to large (you can also implement n㏒n complexity sorting methods such as quick, Hill, merge, and heap sorting to reduce the complexity of the entire algorithm) - //after a string is sorted from small to large, only the adjacent two strings may have a second string beginning with the first string of relationships - for(intI=1;i<arr.length; i++){ - if(Arr[i].indexof (arr[i-1]) ==0) { - return"YES"; in } - } to return"NO"; + } - the}
Problem Solving (conflictphonenumber--conflicting phone numbers)