Huawei OD machine test-real password-2022Q4 volume A-Py/Java/JS


Enter an array of strings on one line. If all substrings of one of the strings starting with index 0 are present in the array, then this string is a potential password. The longest among all potential passwords is the real password. If there are multiple real passwords with the same length, then take the one with the largest lexicographical order as the only real password, and find the only real password.

Example 1:

Import: h he hel hell hello o ok n ni nin ninj ninja

Output: ninja

Explanation: hello, ok, ninja are all potential passwords as requested. Check the length, hello, ninja is the real password. Checking the lexicographic order, ninja is the only true password.

Example 2:

Input:
abcdf

Output:
f

Explanation: abcdf are potential ciphers as requested. Check the length, abcdf is the real password. Checking the lexicographic order, f is the only true password.

java code

import java.util.Scanner;
import java.util.*;
import java.util.stream.Collectors;
 
 
class Main {
    public static int min_times;
	public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        String[] strs = in.nextLine().split(" ");
 
        // 将所有字符串放入哈希集合
        HashSet<String> word_set=new Ha

Guess you like

Origin blog.csdn.net/miao_9/article/details/130213257