就是查找这个单词能不能有两个单词组成,简单的字典树题目

//////////////////////////////////////////////////////////////
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std; #define maxn 26 struct node
{
    int sum;
    node *next[];
}; node *root;
char a[][]; void Insert(char *s);//建立字典树
bool Find(char *s);
bool Query(char *s); int main()
{
    int i, n=;     root = new node();     for(i=; scanf("%s", a[i]) != EOF; i++)
        Insert(a[i]);
   
    for(n=, i=; i<=n; i++)
    {
        if(Query(a[i]))
            printf("%s\n", a[i]);
    }     return ;
} void Insert(char *s)
{
    node *p = root;     for(int i=; s[i]; i++)
    {
        int k = s[i] - 'a';         if(!p->next[k])
            p->next[k] = new node();
        p = p->next[k];
    }     p->sum = ;
}
bool Find(char *s)
{
    node *p = root;     for(int i=; s[i]; i++)
    {
        int k = s[i] - 'a';         if(!p->next[k])
            return false;
        p = p->next[k];
    }     if(p->sum)return true;
    return false;
}
bool Query(char *s)
{
    node *p = root;     for(int i=; s[i]; i++)
    {
        int k = s[i] - 'a';         p = p->next[k];         if(p->sum && Find(s+i+))
            return true;
    }     return false;

}

Hat’s Words hdu-1247的更多相关文章

  1. Hat’s Words HDU - 1247 字典树

    题意:给出数个单词 输出单词 如果该单词 是由字典中的单词组成的 思路:字典树 先把全部建树  然后对于每一个单词进行分割,分别拿两半到字典树里面去找 小心RE! #include<bits/s ...

  2. HDU 1247 - Hat’s Words - [字典树水题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...

  3. HDU 1247 Hat’s Words(字典树变形)

    题目链接:pid=1247" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1247 Pro ...

  4. HDU 1247 Hat’s Words(字典树)

    http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意: 给出一些单词,问哪些单词可以正好由其他的两个单词首尾相连而成. 思路: 先将所有单独插入字典树,然 ...

  5. hdu 1247:Hat’s Words(字典树,经典题)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  6. HDU 1247 Hat's Words (map+string)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. HDU 1247 Hat’s Words (字符串匹配,暴力)

    题意: 给出一堆单词,如果有一个单词可以分成左右串两个单词,并且在所给的一堆单词中存在,就是hat词,统计所有这样的词,并按字典序输出. 思路: 注意定义,一个hat词可以被两部分已经存在的词组成,那 ...

  8. HDU 1247 Hat’s Words

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. hdu 1247 Hat’s Words(字典树)

    Hat's Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  10. HDU 1247 Hat’s Words(字典树活用)

    Hat's Words Time Limit : 2000 / 1000 MS(Java / Others)    Memory Limit : 65536 / 32768 K(Java / Othe ...

随机推荐

  1. Linux磁盘管理:lvcreate 常用命令

    查看当前LV及PV信息: [root@rusky ~]# hostnamectl Static hostname: localhost.localdomain Transient hostname: ...

  2. jqPlot,一个 jQuery这个 JavaScript 框架的绘图插件

    因为项目中需要做报表的功能,于是学习了如何使用jqplot这个绘图插件 结合ajax技术,动态交互后台数据 前前后后花了三四天的时间. 感觉它会出来的想说还可以. 我的后台模板是bootstrap,在 ...

  3. leetcode修炼之路——383. Ransom Note

    题目是这样的 Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

  4. unexpected nil window in _UIApplicationHandleEventFromQueueEvent...

    unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: <UI ...

  5. ExtJs API 下载以及部署

    ExtJs API 下载方法 1.进入sencha官网:https://www.sencha.com/ 2.点击“Docs”进入文档帮助页面:http://docs.sencha.com/ 3.点击左 ...

  6. Media Queries详解--转

    Media Queries直译过来就是“媒体查询”,在我们平时的Web页面中head部分常看到这样的一段代码:  <link href="css/reset.css" rel ...

  7. linux关机重启命令浅析

    linux关机重启命令 今天我们来介绍下linux系统中常用到的关机重启命令—shutdown.halt.reboot.poweroff以及init. shutdown命令 以安全的方式关闭系统或重启 ...

  8. underscorejs-filter学习

    2.6 filter 2.6.1 语法: _.filter(list, predicate, [context]) 2.6.2 说明: 对list集合的每个成员依次进行匹配(根据predicate迭代 ...

  9. 数据库备份工具mysqldump重要参数详解

    1. --single-transaction InnoDB 表在备份时,通常启用选项 --single-transaction 来保证备份的一致性,实际上它的工作原理是设定本次会话的隔离级别为:RE ...

  10. js实现输入验证码

    html部分: <div> <input type="text" id="input" /> <input type=" ...