zoukankan      html  css  js  c++  java
  • poj3630

    trie

    View Code
    #include <iostream>
    #include 
    <cstdio>
    #include 
    <cstdlib>
    #include 
    <cstring>
    using namespace std;

    #define maxl 15
    #define maxn 10005

    struct Node
    {
        Node 
    *next[10];
        
    bool have;
        
    bool end;
    } trie[maxn 
    * maxl];

    int n;
    char st[maxl];
    int ncount;

    bool ins(Node *proot, char *st)
    {
        
    if (proot->end)
            
    return false;
        
    if (st[0== '\0')
        {
            proot
    ->end = true;
            
    return !proot->have;
        }
        
    if (!proot->next[st[0- '0'])
        {
            proot
    ->next[st[0- '0'= trie + ncount;
            ncount
    ++;
            proot
    ->have = true;
            ins(proot
    ->next[st[0- '0'], st + 1);
            
    return true;
        }
        
    return ins(proot->next[st[0- '0'], st + 1);
    }

    void finish(int a)
    {
        
    int b = n - a - 1;
        
    for (int i = 0; i < b; i++)
            scanf(
    "%s", st);
    }

    bool work()
    {
        ncount 
    = 1;
        memset(trie, 
    0sizeof(trie));
        
    for (int i = 0; i < n; i++)
        {
            scanf(
    "%s", st);
            
    if (!ins(trie, st))
            {
                finish(i);
                
    return false;
            }
        }
        
    return true;
    }

    int main()
    {
        
    //freopen("t.txt", "r", stdin);
        int t;
        scanf(
    "%d"&t);
        
    while (t--)
        {
            scanf(
    "%d"&n);
            
    if (work())
                printf(
    "YES\n");
            
    else
                printf(
    "NO\n");
        }
        
    return 0;
    }
  • 相关阅读:
    Beta 冲刺 (5/7)
    Beta 冲刺 (4/7)
    软件产品案例分析(团队)
    Beta 冲刺 (3/7)
    Beta 冲刺 (2/7)
    Beta 冲刺 (1/7)
    BETA 版冲刺前准备
    个人作业——软件工程实践总结作业
    Beta 答辩总结
    Beta 冲刺 (7/7)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2105676.html
Copyright © 2011-2022 走看看