/*
PROG: prefix
ID :
LANG: C++
*/
#include <string.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <memory.h>
#include <algorithm>
using namespace std;
struct Trie_Node
{
bool IsEnd;
Trie_Node *branch[26];
Trie_Node(): IsEnd( false )
{
memset( branch, 0, sizeof(branch) );
}// Init
};
class Trie
{
public:
Trie();
void Trie_Insert( char tt[] );
void Trie_Find( long j );
private:
Trie_Node *root;
}t; // type class "Trie" object t
long slen;
bool prefix[200400];
char line[204], ss[200400];
Trie::Trie()
{
root = new Trie_Node();
}// Trie
void Trie::Trie_Insert( char tt[] )
{
Trie_Node *ptr = root;
int tlen = strlen( tt );
for ( int i=0; i<tlen; ++i )
{
if ( ptr->branc
USACO 2.3.1 Longest Prefix --- Trie
最新推荐文章于 2016-12-02 11:41:21 发布
该博客介绍了如何使用Trie数据结构解决USACO中找到最长公共前缀的问题。通过C++实现Trie节点和插入、查找功能,读取输入数据并进行处理,最终输出最长公共前缀的长度。
摘要由CSDN通过智能技术生成