1022. Digital Library (30)

考察倒排索引

#include
#include
#include
#include
#include
#include
using namespace std;

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		//build map
		map> queryMap[5];
		while(n--)
		{
			getchar();
			string id, title, author, wordList, publisher, year;
			getline(cin, id);
			getline(cin, title); getline(cin, author);
			getline(cin, wordList); 
			getline(cin, publisher); cin>>year;
			queryMap[0][title].push_back(id); queryMap[1][author].push_back(id);
			queryMap[3][publisher].push_back(id); queryMap[4][year].push_back(id);
			istringstream istr(wordList);
			while(!istr.eof())
			{
				string word;
				istr>>word;
				queryMap[2][word].push_back(id);
			}
		}
		//sort first
		for(int i = 0; i < 5; ++i)
		{
			map>::iterator it;
			for(it=queryMap[i].begin(); it!=queryMap[i].end(); it++)
				sort(it->second.begin(), it->second.end());
		}
		//query
		int m;
		scanf("%d",&m);
		while(m--)
		{
			int index; string q;
			scanf("%d: ", &index);
			getline(cin, q);
			printf("%d: ", index);
			cout<>::iterator it;
			it = queryMap[index].find(q);
			if(it!=queryMap[index].end())
			{
				std::vector result = queryMap[index][q];
				for(int i = 0; i < result.size(); ++i)
					cout<


 

你可能感兴趣的:(浙大PAT,面试编程训练)