java倒排索引

import java.util.ArrayList;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		
		TreeMap> books=new TreeMap<>();
		ArrayList lines=new ArrayList<>();
		
		//输入,注意i是行号
		for(int i=1;;i++)				
		{
			String tempLine=sc.nextLine();
			
			if(tempLine.equals("!!!!!"))
				break;					//结束标志
			
			lines.add(tempLine);
			String[] words=tempLine.split(" ");
			for(String word:words) 
			{
				if(books.containsKey(word))
				{
					if(!books.get(word).contains(i))
						books.get(word).add(i);
				}
				else
				{
					ArrayList rowIndex=new ArrayList<>();
					rowIndex.add(i);
					books.put(word, rowIndex);
				}
			}
		}
		//按序输出
		ArrayList>> lists=new ArrayList<>();
		for(String s:books.keySet()) {
			System.out.print(s+"=");
			System.out.println(books.get(s));
		}
		//判断输出
		while(true)
		{
			String[] keys=sc.nextLine().split(" ");
			ArrayList> indexList=new ArrayList<>();
			for(int i=0;i

你可能感兴趣的:(java,eclipse)