hdu 1800 trie树

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<map>
#include<queue>
#include <deque>
#include <list>
#include <ctime>
#include <stack>
#include <vector>
#include<iomanip>
#include<set>
#define Maxn
#define mod
typedef long long ll;
#define FOR(i,j,n) for(int i=j;i<=n;i++)
#define DFR(i,j,k) for(int i=j;i>=k;--i)
#define lowbit(a) a&-a
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define mem(a) memset(a,0,sizeof(a))
#define eps 1e-9
const int inf = 0x3f3f3f3f;
const double pi = acos(-1.0);
using namespace std;
int m;
struct node
{   node * next[10];
    int num;
    node()
    {   FOR(i,0,9)  next[i]=0;
        num=0;
    }
}*root;
void Insert(char s[])
{   int k = 0;
    node *p =root;
    while(s[k]!='\0')
    {   if(!p->next[s[k]-'0'])
        p->next[s[k]-'0'] = new node();
        p=p->next[s[k]-'0'];
        k++;
    }
    p->num++;
    if(p->num>m) m =p->num;
}
int main()
{   int n;
    while(cin>>n)
    {   m=0;root =new node();
        FOR(i,0,n-1)
        {   char s[33];
            cin>>s;
            int j=0;
            while(s[j]=='0')
                j++;
            Insert(s+j);
        }
        cout<<m<<endl;
    }
    return 0;
}


    原文作者:Trie树
    原文地址: https://blog.csdn.net/Griffin_0/article/details/51135122
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞