geline(cin,s)不能处理里面隔着回车的数据
害我一直wa
#include<cstdio>
#include<iostream>
#include<map>
#include<cstring>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int n,m;
map<string,int> mat;
vector<string> str[220];
vector<string>::iterator it1;
vector<string>::iterator it2;
string s;
string tmp;
int num[220];
int main()
{
while(cin>>n)
{
mat.clear();
for(int i=0;i<n;i++)
{
str[i].clear();
fflush(stdin);
cin>>s;
mat[s]=i;
fflush(stdin);
while(getline(cin,s))
if(s!="")break;
int len=s.length();
tmp="";
for(int j=0;j<len;j++)
{
if(s[j]==' ')
{
if(tmp!="")
str[i].push_back(tmp);
tmp="";
}
else
tmp+=s[j];
}
if(tmp!="")
str[i].push_back(tmp);
}
cin>>m;
while(m--)
{
int cnt=0;
tmp="";
fflush(stdin);
while(getline(cin,s))
if(s!="")break;
int len=s.length();
for(int i=0;i<len;i++)
{
if(s[i]==' ')
{
if(tmp!="")
num[cnt++]=mat[tmp];
tmp="";
}
else
tmp+=s[i];
}
if(tmp!="")
num[cnt++]=mat[tmp];
sort(str[num[0]].begin(),str[num[0]].end());
int ans=0;
for(it1=str[num[0]].begin();it1!=str[num[0]].end();it1++)
{
int flag1=1;
for(int i=1;i<cnt;i++)
{
int flag2=0;
for(it2=str[num[i]].begin();it2!=str[num[i]].end();it2++)
if((*it1)==(*it2))
{
flag2=1;
break;
}
if(flag2==0)
{
flag1=0;
break;
}
}
if(flag1)
{
if(ans!=0)
cout<<" ";
cout<<*it1;
ans++;
}
}
if(ans==0)
cout<<"NO";
cout<<endl;
}
}
return 0;
}