传奇网页游戏排行郑州seo代理公司
这道题我们只要标记每个字符串出现在哪几行就行了,但是直接用 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;
}