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

//////////////////////////////////////////////////////////////
#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. MsSql省市联动表

    drop table area CREATE TABLE [dbo].[Area] ( , ) NOT NULL , ) COLLATE Chinese_PRC_CI_AS NOT NULL , ) ...

  2. noip 2015 运输计划 (lca+二分)

    /* 95 最后一个点T了 qian lv ji qiong 了 没学过树剖 听chx听xzc说的神奇的方法 Orz 首先求出每个计划的路径长度 这里写的倍增 然后二分答案 对于每个ans 统计> ...

  3. Android 自定义日历

    好久没来写博客了,这半年多发生了好多的事情,废话不多说,今天在公司里比较闲在,写一篇最近写的公司用到的控件——日历控件. 控件的功能比较少,根据需求只有选择开始时间和结束时间并返回时间段. 效果图如下 ...

  4. 本地代码上传 -> Github

    首先在控制台cd到你的本地项目,这里以teat为例 1.执行命令:  git init 2.将项目文件添加到仓库中:  git add . (可以是指定文件,将“.”转换为指定文件) 3.接下来com ...

  5. POJ3185 The Water Bowls(反转法or dfs 爆搜)

    POJ3185 The Water Bowls 题目大意: 奶牛有20只碗摆成一排,用鼻子顶某只碗的话,包括左右两只在内的一共三只碗会反向,现在给出碗的初始状态,问至少要用鼻子顶多少次才能使所有碗都朝 ...

  6. hdu1301 Jungle Roads (Prim)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1301 依旧Prim............不多说了 #include<iostream> ...

  7. python密码处理(可用于生产模式)

    import os from hashlib import sha256 from hmac import HMAC def encrypt_password(password, salt=None) ...

  8. ext中嵌入flash

    方法1: xtype: 'fieldset', border: 0, title: "", items[{ xtype: 'flash', url: 'Test.swf' }] u ...

  9. Thinkphp发布文章获取第一张图片为缩略图实现方法

    正则匹配图片地址获取第一张图片地址 此为函数 在模块或是全局Common文件夹中的function.php中 /** * [getPic description] * 获取文本中首张图片地址 * @p ...

  10. mysql 表格中的数据量过大,修改数据库字段信息会花费很长的时间

    遇到几百万的数据操作遇到很多问题,比如分区,比如分表,sql语句的效率问题.努力学习好mysql优化还是很有必要的.