全WA,没有多余的空格和换行。
P3879 [TJOI2010]阅读理解
#include <iostream>
#include <queue>
#include <map>
using namespace std;
map<string, queue<int>> a;
int n, m;
int main() {
string s;
cin >> n;
for (int i = 1; i <= n; i++) {
int l;
cin >> l;
for (int j = 1; j <= l; j++) {
cin >> s;
a[s].push(i);
}
}
cin >> m;
for (int i = 1; i <= m; i++) {
cin >> s;
queue<int> q=a[s];//防止查询同样的单词
while(!empty(q)){
cout<<q.front();
q.pop();
if(!empty(q))//防止输出多余空格
cout<<" ";
}
if(i!=m&&m!=1)//防止输出多余换行
cout<<endl;
}
return 0;
}