/**
字典树
判断是否存在一个字符串为另一个的前缀。
字典树果然还是不能动态开辟空间呢,TLE的伤不起鸟。
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define N 100000
struct tireTree
{
bool isNum;
tireTree *tr[10];
}tt[N];
struct Phone
{
char str[11];
int len;
}s[N];
bool cmp(Phone a,Phone b)
{
return a.len < b.len;
}
tireTree *ps;
bool insert(string s,tireTree *&rt)
{
int num;
if(rt == NULL)
rt = ps++;
tireTree *loc = rt;
for(int i = 0; s[i]; ++i)
{
num = s[i] - '0';
if(loc->tr[num] == NULL)
loc -> tr[num] = ps++;
loc = loc->tr[num];
if(loc -> isNum)
return 0;
}
loc-&g
[字典树 ] poj 3630 Phone list
最新推荐文章于 2020-10-04 21:18:14 发布
这篇博客介绍如何利用字典树(Trie Tree)解决POJ 3630题目,即判断一组字符串中是否存在某个字符串是其他字符串的前缀。文章通过C++实现了一个字典树结构,并展示了如何插入字符串以及检查前缀。在处理过程中,博主发现不能动态开辟空间会导致TLE(Time Limit Exceeded)错误。
订阅专栏 解锁全文
4229

被折叠的 条评论
为什么被折叠?



