Hat’s Words hdu-1247
就是查找这个单词能不能有两个单词组成,简单的字典树题目
#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的更多相关文章
- Hat’s Words HDU - 1247 字典树
题意:给出数个单词 输出单词 如果该单词 是由字典中的单词组成的 思路:字典树 先把全部建树 然后对于每一个单词进行分割,分别拿两半到字典树里面去找 小心RE! #include<bits/s ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- HDU 1247 Hat’s Words(字典树变形)
题目链接:pid=1247" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1247 Pro ...
- HDU 1247 Hat’s Words(字典树)
http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意: 给出一些单词,问哪些单词可以正好由其他的两个单词首尾相连而成. 思路: 先将所有单独插入字典树,然 ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 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 ...
- HDU 1247 Hat’s Words (字符串匹配,暴力)
题意: 给出一堆单词,如果有一个单词可以分成左右串两个单词,并且在所给的一堆单词中存在,就是hat词,统计所有这样的词,并按字典序输出. 思路: 注意定义,一个hat词可以被两部分已经存在的词组成,那 ...
- HDU 1247 Hat’s Words
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1247 Hat’s Words(字典树)
Hat's Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- HDU 1247 Hat’s Words(字典树活用)
Hat's Words Time Limit : 2000 / 1000 MS(Java / Others) Memory Limit : 65536 / 32768 K(Java / Othe ...
随机推荐
- Linux防火墙配置
防火墙命令 service iptables stop --停止 service iptables start --启动文件 /etc/sysconfig/iptables # Firewall c ...
- Android传感器的使用(GravieySensor)
这里以重力传感器为例说明 第一步:创建一个SensorManager对象,用来管理或者获取传感器 SensorManager sm = (SensorManager) this.getSystemSe ...
- C#反射—解决类的实例化问题
利用简单工厂模式来改进抽象工厂使用的复杂性(抽象工厂详见 设计模式之—抽象工厂模式) 数据表(User)业务处理接口(IUser) namespace FactoryMethodPatternDB.C ...
- 使用WMI来控制Windows目录 和windows共享机制
1.使用WMI来控制Windows目录 本文主要介绍如何使用WMI来查询目录是否存在.文件是否存在.如何建立目录.删除目录,删除文件.如何利用命令行拷贝文件,如何利用WMI拷贝文件 using Sys ...
- 利用TOAD实现把EXCEL数据导入oracle数据库
利用TOAD实现把EXCEL数据导入oracle数据库 工具: Toad11.7z(百度搜索,直接下载) 1.将Excel文件中某些字段导入到Oracle数据库的对应表 连接想要导入的数据库 ,然 ...
- Xcode 的正确打开方式——Debugging(转)
转自CocoaChina http://www.cocoachina.com/ios/20150225/11190.html 程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不 ...
- JDK1.5中LOCK,Condition的使用
import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.uti ...
- linux ulimit的使用,如何产生core文件,调试段错误
---恢复内容开始--- 下面先简单介绍下ulimit命令: 1. limit -a 可以查看系统各种资源的限制,如: core文件大小,数据段的大小等. $ ulimit -a core file ...
- 8个不可不知的Mac OS X专用命令行工具(转)
OS X的终端下通用很多Unix的工具和脚本.如果从Linux迁移到OS X会发现很多熟悉的命令和脚本工具,其实并没有任何区别. 但是OS X也提供了很多其他系统所没有的特别的命令行工具.我们推荐8个 ...
- Java学习----构造方法的重载
一个类中有多个同名的参数不一样(参数的个数,参数的类型,参数的顺序)的构造方法 public class Student { public Student() { System.out.println ...