#include<iostream>
#include<map>
#include<string>
#include<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;
struct node{
node *next[26];
char str[13];
};
node root,*cur;
void insert(char *b,char *a)
{
node *cur = &root;
node *newnode;
int len1=strlen(a);
for(int i=0;i<len1;i++)
{
int id = a[i]-'a';
if(cur->next[id]==NULL)
{
newnode = new node;
for(int l=0;l<26;l++)
newnode->next[l]=NULL;
cur->next[id] = newnode;
cur = newnode;
}
else
cur = cur->next[id];
}
strcpy(cur->str,b);
}
int find(char *a)
{
cur = &root;
int l=strlen(a);
for(int i=0;i<l;i++)
{
if(cur->next[a[i]-'a']!=NULL)
{
cur = cur->next[a[i]-'a'];
}
else
{
//printf("eh\n");
return 0;
}
}
printf("%s\n",cur->str);
return 1;
}
int main()
{
char a[20],b[20],c[100];
while(gets(c))
{
if(strlen(c)==0)break;
sscanf(c,"%s %s",a,b);
insert(a,b);
}
while(scanf("%s",a)!=EOF)
{
if(!find(a))
printf("eh\n");
}
}
output limited exceeded 要不是输出多余的东西,要不就是输出进入死循环,没有退出条件.有输出语句的不要写进死循环
转载请注明原文地址: https://ju.6miu.com/read-1299682.html