

























现在给你N个单词和一些查询,请输出提示结果,为了简化这个问题,只需要输出以查询词为前缀的并且按字典序排列的最前面的8个单词,如果符合要求的单词一个也没有请只输出当前查询词。
10 a ab hello that those dict youdao world your dictionary 6 bob d dict dicti yo z
bob dict dictionary dict dictionary dictionary youdao your z
没来得及提交,也不知道对不对。
1 import java.util.Scanner;
2
3 public class Main {
4 public static void main(String[] args) {
5 Scanner in = new Scanner(System.in);
6 int counti = in.nextInt();
7 String[] inputS = new String[counti];
8 for(int i=0;i<counti;i++)
9 {
10 inputS[i]=in.next();
11 }
12 int counts = in.nextInt();
13 String[] result = new String[counts];
14 String[] ss = new String[counts];
15 for(int i=0;i<counts;i++)
16 {
17 result[i]="";
18 ss[i]=in.next();
19 for(int j =0;j<counti;j++)
20 {
21 if(inputS[j].startsWith(ss[i]))
22 {
23 result[i]+=" "+inputS[j];
24 }
25 }
26 if(result[i].equals(""))
27 result[i]=ss[i];
28 else
29 result[i]=result[i].trim();
30 }
31 for(int i = 0; i<counts;i++)
32 {
33 System.out.println(result[i]);
34 }
35 }
36 }
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。