import java.util.*;
public class Main {
? ? public static void main(String[] args) {
? ? ? ? Scanner in = new Scanner(System.in);//新創(chuàng)建一個輸入的Scanner 對象熊痴,然后賦值給in
? ? ? ? Map<String, List<Integer>> map = new HashMap();//Map 是 interface,HashMap 是 實現(xiàn)類
? ? ? ? int n = 0;
? ? ? ? List<String> lines = new ArrayList<>();
? ? ? ? while (true) {
? ? ? ? ? ? String line = in.nextLine();
? ? ? ? ? ? if (line.equals("!!!!!"))
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? n++;
? ? ? ? ? ? lines.add(line);
? ? ? ? ? ? String[] words = line.split(" ");
? ? ? ? ? ? for (String word : words) {
? ? ? ? ? ? ? ? if (map.containsKey(word)) {
? ? ? ? ? ? ? ? ? ? if (map.get(word).contains(n))
? ? ? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? ? ? map.get(word).add(n);
? ? ? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? ? ? List<Integer> index = new ArrayList<>();
? ? ? ? ? ? ? ? ? ? index.add(n);
? ? ? ? ? ? ? ? ? ? map.put(word, index);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? List<Map.Entry<String, List<Integer>>> list = new ArrayList<>(map.entrySet());
? ? ? ? Collections.sort(list, Comparator.comparing(Map.Entry::getKey));//冒泡排序,效率對比
? ? ? ? for (int i = 0; i < list.size(); i++) {
? ? ? ? ? ? System.out.println(list.get(i));
? ? ? ? }
? ? ? ? while (true) {
? ? ? ? ? ? String[] keys = in.nextLine().split(" ");
? ? ? ? ? ? List<List<Integer>> index = new ArrayList<>();
? ? ? ? ? ? for (int i = 0; i < keys.length; i++) {
? ? ? ? ? ? ? ? for (int j = 0; j < list.size(); j++) {
? ? ? ? ? ? ? ? ? ? if (list.get(j).getKey().equals(keys[i])) {
? ? ? ? ? ? ? ? ? ? ? ? index.add(list.get(j).getValue());
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? if (index.size() == 0) {
? ? ? ? ? ? ? ? System.out.println("found 0 results");
? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? }
? ? ? ? ? ? List<Integer> result = index.get(0);
? ? ? ? ? ? if (keys.length >= 2) {
? ? ? ? ? ? ? ? for (int i = 1; i < index.size(); i++) {
? ? ? ? ? ? ? ? ? ? result.retainAll(index.get(i));
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (result.size()==0){
? ? ? ? ? ? ? ? ? ? System.out.println("found 0 results");
? ? ? ? ? ? ? ? ? ? continue;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? System.out.println(result);
? ? ? ? ? ? for (int i : result) {
? ? ? ? ? ? ? ? System.out.println("line "+i+":"+lines.get(i-1));
? ? ? ? ? ? }
? ? ? ? }
? ? }
}