hdu1247-trie树
来源:互联网 发布:网络里麻瓜是什么意思 编辑:程序博客网 时间:2024/06/07 06:12
hdu1247
#include<cstdio>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
char s[50000][105];
struct tree
{
tree *next[26];
int v;
};
tree root;
void build(char*str)
{
tree *p=&root;
tree *q;
int len=strlen(str);
for(int i=0;i<len;i++)
{
int id=str[i]-'a';
if(p->next[id]!=NULL)
p=p->next[id];
else
{
q=(tree*) new tree;
q->v=-1;
for(int j=0;j<26;j++)
q->next[j]=NULL;
p->next[id]=q;
p=p->next[id];
}
}
p->v=1;
}
int findd(char *str)
{
tree *p=&root;
int len=strlen(str);
for(int i=0;i<len;i++)
{
int id=str[i]-'a';
p=p->next[id];
if(p==NULL)
return -1;
}
return p->v;
}
int main()
{
int cnt=0;
for(int i=0;i<26;i++)
root.next[i]=NULL;
while(scanf("%s",s[cnt])!=EOF)
{
build(s[cnt]);
cnt++;
}
char s1[100]={'\0'},s2[100]={'\0'};
for(int i=0;i<cnt;i++)
{
int len=strlen(s[i]);
for(int j=1;j<len;j++)
{
strcpy(s1,s[i]);
s1[j]='\0';
strcpy(s2,s[i]+j);
if(findd(s1)==1&&findd(s2)==1)
{
printf("%s\n",s[i]);
break;
}
}
}
return 0;
}
- hdu1247(trie树)
- hdu1247-trie树
- HDU1247-Hat’s Words(trie树)
- HDU1247 Hat’s Words 【trie树】
- hdu1247 Hat's words trie树
- HDU1247 Hat's Words(Trie树,map)
- 【Trie】【HDU1247】【Hat’s Wordsfd2】
- HDU1247 Hat’s Words【Trie】
- Hat's Words hdu1247 trie
- HDU1247字典树
- hdu1247 字典树模板
- HDU1247(字典树)
- HDU1247 字典树
- hdu1247字典树
- hdu1247字典树
- 字典树hdu1247
- hdu1247字典树
- hdu1247(字典树/map)
- Java判断List中有无重复元素
- 关于HTTP请求的论述
- [poj3159]
- checkbox多项选择当前的position信息提交
- 剑指offer的java实现(1)
- hdu1247-trie树
- HDU.1233 还是畅通工程(Prim)
- linux中poll,epoll,select区别,等等
- Android 自定义控件基础 canvas paint
- 百练 2775:文件结构“图”(递归法)
- Java开发——JavaScript初步学习
- python 个人学习笔记1
- 基于RESTful类型的webService
- 网络直播步入“剩者为王”的时代,三大层面将成决定性因素