struct node {
int count;
node* tire[26];
}* a;
void init() {
a = new node();
for (int i = 0; i < 26; i++) {
a->tire[i] = NULL;
}
}
void insert(char str[]) {
int len = 0 , cur = 0;
node* head = a;
len = strlen(str);
for (int i = 0; i < len; i++) {
cur = (int)(str[i] - 'a');
if (head->tire[cur] == NULL) {
head->tire[cur] = new node();
head = head->tire[cur];
head->count = 1;
for (int i = 0; i < 26; i++) {
head->tire[i] = NULL;
}
}
else {
head = head->tire[i];
head->count++;
}
}
}
int search(char str[]) {
int len, m;
node* head = a;
len = strlen(str);
char ans[25];
for (int i = 0; i < len; i++) {
m = str[i] - 'a';
head = head->tire[m];
ans[i] = str[i];
ans[i + 1] = '\0';
if (head->count == 1) {
printf("%s %s\n", str, ans);
return 0;
}
}
printf("%s %s\n", str, ans);
}