种花家生日快乐! hdu 1251 简单的字典树
来源:互联网 发布:网络摄像头哪个品牌好 编辑:程序博客网 时间:2024/04/30 05:10
套模板就好了
#include<iostream>#include<cstdio>using namespace std;#define NULL 0const int num_chars = 26;struct Trie_node{int data;Trie_node* branch[num_chars];Trie_node(){data = NULL;for (int i = 0; i < num_chars; i++){branch[i] = NULL;}}};Trie_node* root = new Trie_node;int insert(char* word){int result = 1,code;Trie_node* location = root;char* sword = word;while (location != NULL && *sword != '\0'){code = *sword - 'a';if (location->branch[code] == NULL){location->branch[code] = new Trie_node;}location = location->branch[code];location->data++;sword++;}if (*sword == '\0'){return 1;}return 0;}int search(char* word){int code, result = 1;Trie_node* location = root;char* sword = word;while (location != NULL && *sword != '\0'){code = *sword - 'a';if (location->branch[code] == NULL){return 0;}location = location->branch[code];sword++;}if (*sword != '\0'){return 0;}return location->data;}int main(){//freopen("TestDate.txt", "r", stdin);char s[12];while (gets(s) && s[0]){insert(s);}while (gets(s)){cout << search(s) << endl;}return 0;}
0 0
- 种花家生日快乐! hdu 1251 简单的字典树
- hdu 1251 字典树的简单应用
- hdu 1251简单字典树
- hdu 1251 简单字典树
- hdu-1251统计难题-字典树的简单应用
- HDU 1251 1671 (简单字典树)
- HDU 1075(简单字典树)
- hdu 2846 简单字典树
- hdu-1247 简单map的应用。(字典树)
- HDU 1761—简单的字典树,需要释放内存
- hdu--1251--统计难题(字典树简单)
- hdu 1251(字典树)
- hdu 1251 字典树
- HDU 1251 字典树
- hdu 1251 字典树
- hdu 1251 字典树
- HDU-1251,字典树
- HDU 1251 字典树
- D3D11基础教程三之VertexShader,PixelShader,buffer
- hadoop2.7.3 mahout 0.9 遇到问题
- VIM常用快捷键
- 各种排序方法总结
- 【逆向】逆向工厂(二):静态分析技术
- 种花家生日快乐! hdu 1251 简单的字典树
- Android 图片的三级缓存
- c++备忘录1
- 【网络】 如何记住OSI七层协议模型,脑洞大开有木有?
- C/C++ 笔试、面试题目大汇总1
- C++ TUTORIAL - MEMORY ALLOCATION - 2016
- UML中关系(4+4)
- hdu4511 小明系列故事——女友的考验(AC自动机+dp)
- Unity插件NGUI实现技能冷却效果