目录

蓝桥杯备考unordered_map用法之阅读理解

目录

蓝桥杯备考:unordered_map用法之阅读理解

https://i-blog.csdnimg.cn/direct/6b4572d9a562425680517bb64729987a.png

这道题我们只要标记每个字符串出现在哪几行就行了,但是直接用 vector存的话就会产生重复,有的字符串可能在一行内出现了两次,就会打印两次,这时候我们可以套一个set来去重

#include <iostream>
#include <unordered_map>
#include <set>
using namespace std;
unordered_map <string,set<int>> mp;
int n;
int main()
{
	cin >> n;
	for(int i = 1;i<=n;i++)
	{
		int t;cin >> t;
		string s;
		for(int j = 1;j<=t;j++)
		{
			cin >> s;
			mp[s].insert(i);
		}
	}
	int k;cin >> k;
	string t;
	while(k--)
	{
		cin >> t;
		for(auto e : mp[t])
		{
			cout << e << " ";
		 } 
		 cout << endl;
	}
	
	
	
	
	
	
	return 0;
}