破题 又逼着用stl 卡内存 trie树太耗了 水不过去
用set存字符串 set可以自己按一定顺序存 且没有重复的 再用lower_bound二分查找字符串的第一次出现 接着往后找就行了
#include <iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#include<set>
#include<string>
using namespace std;
#define N 10010
set<string>q;
set<string>::iterator it;
int kk;
string ys = "sun";
char ss[];
bool cmp(string s)
{
int i,tk = (int)s.size();
if(tk<kk)
return false;
for(i = ; i < kk ; i++)
{
if(s[i]!=ss[i])
return false;
}
return true;
}
int main()
{
char c;
q.insert(ys);
while(cin>>c)
{
cin>>ss;
if(c=='?')
{
cout<<ss<<endl;
kk = strlen(ss);
if(q.size())
{
it = lower_bound(q.begin(),q.end(),ss);
int k;
for(k=; it!=q.end()&&cmp(*it)&&k<;it++,k++)
cout<<" "<<(*it)<<endl;
}
}
else
{
q.insert(ss);
}
getchar();
}
return ;
}