#include<iostream>
#include<string>
#include<vector>
#define MAX_NUM 26
using namespace std;
class TrieNode{
public:
bool isWord;
char c;
int count;
//TrieNode *next[MAX_NUM]{nullptr};
TrieNode(char w):c(w),isWord(false),count(0){}
TrieNode *next[MAX_NUM]{nullptr};
};
class TrieTree{
private:
TrieNode *root;
public:
TrieTree(){
root = new TrieNode(' ');
}
void add(string s);
void _output(TrieNode *root,string print);
void output(char c);
TrieNode *getRoot();
};
TrieNode * TrieTree::getRoot(){
return root;
}
void TrieTree::_output(TrieNode *head,string print){
if(head->isWord)
cout<<print<<endl;
for(int i=0;i<MAX_NUM;i++){
if(head->next[i]!=nullptr){
print+=('a'+i);
_output(head->next[i],print);
print.erase(print.end()-1,print.end());
}
}
}
void TrieTree::output(char c)
{
int j=c-'a';
string s;
s+=c;
_output(root->next[j],s);
}
void TrieTree::add(string s){
TrieNode *t=root;
for(int i=0;i<s.size();i++){
if(!t->next[s[i]-'a'])
t->next[s[i]-'a']=new TrieNode(s[i]);
t=t->next[s[i]-'a'];
t->count++;
}
t->isWord=true;
}
int main(){
TrieTree a;
a.add("abdf");
a.add("egg");
a.add("aa");
char c;
cin>>c;
a.output(c);
}
输入a