zoukankan      html  css  js  c++  java
  • POJ 2503

    #include<iostream>
    #include<string>
    #define kind 30
    using namespace  std;
    
    class trie
    {
    private:
        struct trienode
        {
            trienode * next[kind];    
            char c[kind];
            int branch;
            trienode()
            {
                branch=0;
                int i;
                for(i=0;i<kind;i++)
                    next[i]=NULL;    
                for(i = 0; i < kind; ++ i)
                    c[i] = ' ';
            }
        };
        trienode * root;
    public:
        trie()
        {
            root=NULL;
        }
        void insert(char s[],char s1[])
        {
            trienode * location = root;
            if(location == NULL)
                location = root = new trienode();
            int i = 0,k;
            while(s[i])
            {
                k=s[i]-'a';
                if(location->next[k])
                    location->next[k]->branch++;
                else
                {
                    location->next[k]=new trienode();
                    location->next[k]->branch++;
                }
                i++;
                location = location->next[k];    
            }
            memcpy(location->c,s1,strlen(s1));
            //cout<<location->c<<endl;//<<" 插入"<<endl;
        }
        int search(char s[])
        {
            trienode * location = root;
            if(!location) 
                return 0;
            int k,i = 0,ans;
            while(s[i])
            {
                k=s[i] - 'a';
                if(!location->next[k])
                return 0;
                ans = location->next[k]->branch;
                location = location->next[k];
                i++;
            }
            if(location)
            {
                for(i = 0;location->c[i] != ' '; ++ i)
                    cout<<location->c[i];
                cout<<endl;
            }
            return ans;
        }
        
    };
    int main()
    {
        //freopen("acm.acm","r",stdin);
        char b[11];
        char c[11];
        char k;
        int i = 0;
        int j;
        string u;
        int num;
        trie mytrie;
        while(cin>>b,k = getchar(),cin>>c)
        {
            //k = getchar();
        //    cout<<b<<" "<<c<<endl;
            if(k != ' ')
                break;
            mytrie.insert(c,b);
            ++ i;
        }
    //    cout<<"-----------"<<endl;
        if(!mytrie.search(b))
                cout<<"eh"<<endl;
        if(!mytrie.search(c))
                cout<<"eh"<<endl;
        while(cin>>b)
        {
        //    cout<<b<<endl;
            if(!mytrie.search(b))
                cout<<"eh"<<endl;
        }
        return 0;
    }
  • 相关阅读:
    Python的命名空间及作用域
    STM32 RTC时钟的配置
    STM32 输入捕获配置
    stm32 看门狗配置
    led灯的驱动电流和电阻
    STM32中TIMx的映射及其通道
    STM32中断定时,控制LED灯
    STM32 用c语言控制4个LED灯从左向右无限流动
    SYSTEMsyssys.c:33:7: error: expected '(' before 'void' __ASM void MSR_MSP(u32 addr)
    STM32 PWM输出(映射)
  • 原文地址:https://www.cnblogs.com/gavinsp/p/4568455.html
Copyright © 2011-2022 走看看