#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct snode{
char str[20];
int len;
bool operator <(const snode& other) const
{
if(len<=other.len)
return true;
else
return false;
}
}Snode;
Snode mys[50000];
typedef struct tnode{
char name[20];
}Tnode;
bool mycompare(const Tnode& a,const Tnode& b)
{
if(strcmp(a.name,b.name)==-1)
{
return true;
}
else
return false;
}
Tnode mynode[50000];
typedef struct node{
node(){
isword=false;
for(int i=0;i<26;i++)
{
child[i]=NULL;
}
}
bool isword;
node* child[26];
}Node;
Node* root=NULL;
bool search( char* str1,int a,int b)
{
Node* temp=root;
for(int i=a;i<=b;i++)
{
if(temp->child[str1[i]-'a']!=NULL)
{
temp=temp->child[str1[i]-'a'];
}
else{
return false;
}
}
if(temp->isword)
return true;
else
return false;
}
void insert(const char* str2)
{
if(root==NULL)
root=new Node();
int len=strlen(str2);
Node* temp=root;
for(int i=0;i<len;i++)
{
if(temp->child[str2[i]-'a']==NULL)
{
temp->child[str2[i]-'a']=new Node();
}
else{
}
temp=temp->child[str2[i]-'a'];
}
temp->isword=true;
}
int main()
{
//freopen("in.txt","r",stdin);
char str[20];
int i=0;
while(scanf("%s",str)!=EOF)
{
strcpy(mys[i].str,str);
mys[i++].len=strlen(str);
}
sort(mys,mys+i);
int t=0;
for(int j=0;j<i;j++)
{
insert(mys[j].str);
if(j>=2)
{
for(int k=0;k<strlen(mys[j].str)-1;k++)
{
if(search(mys[j].str,0,k)&&search(mys[j].str,k+1,strlen(mys[j].str)-1))
{
strcpy(mynode[t++].name,mys[j].str);
break;
}
}
}
}
sort(mynode,mynode+t,mycompare);
for(int m=0;m<t;m++)
{
printf(mynode[m].name);
printf("\n");
}
return 0;
}
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct snode{
char str[20];
int len;
bool operator <(const snode& other) const
{
if(len<=other.len)
return true;
else
return false;
}
}Snode;
Snode mys[50000];
typedef struct tnode{
char name[20];
}Tnode;
bool mycompare(const Tnode& a,const Tnode& b)
{
if(strcmp(a.name,b.name)==-1)
{
return true;
}
else
return false;
}
Tnode mynode[50000];
typedef struct node{
node(){
isword=false;
for(int i=0;i<26;i++)
{
child[i]=NULL;
}
}
bool isword;
node* child[26];
}Node;
Node* root=NULL;
bool search( char* str1,int a,int b)
{
Node* temp=root;
for(int i=a;i<=b;i++)
{
if(temp->child[str1[i]-'a']!=NULL)
{
temp=temp->child[str1[i]-'a'];
}
else{
return false;
}
}
if(temp->isword)
return true;
else
return false;
}
void insert(const char* str2)
{
if(root==NULL)
root=new Node();
int len=strlen(str2);
Node* temp=root;
for(int i=0;i<len;i++)
{
if(temp->child[str2[i]-'a']==NULL)
{
temp->child[str2[i]-'a']=new Node();
}
else{
}
temp=temp->child[str2[i]-'a'];
}
temp->isword=true;
}
int main()
{
//freopen("in.txt","r",stdin);
char str[20];
int i=0;
while(scanf("%s",str)!=EOF)
{
strcpy(mys[i].str,str);
mys[i++].len=strlen(str);
}
sort(mys,mys+i);
int t=0;
for(int j=0;j<i;j++)
{
insert(mys[j].str);
if(j>=2)
{
for(int k=0;k<strlen(mys[j].str)-1;k++)
{
if(search(mys[j].str,0,k)&&search(mys[j].str,k+1,strlen(mys[j].str)-1))
{
strcpy(mynode[t++].name,mys[j].str);
break;
}
}
}
}
sort(mynode,mynode+t,mycompare);
for(int m=0;m<t;m++)
{
printf(mynode[m].name);
printf("\n");
}
return 0;
}