POJ 2503 Babelfish 字典树

#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 要不是输出多余的东西,要不就是输出进入死循环,没有退出条件.有输出语句的不要写进死循环
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值