hihocoder #1014 trie树
来源:互联网 发布:sql case null 编辑:程序博客网 时间:2024/06/11 17:13
裸的trie树,无它。
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <string>#include <cmath>using namespace std;#define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl;class trie{private: int n, m; static const int maxn = 1e5 + 13; char word[maxn]; struct node { int num; node* son[26]; node(void) { num = 0; memset(son, 0, sizeof(son)); } } *root; int ans;public: void input(void) { root = new node; scanf("%d", &n); while (n--) { scanf("%s", word); add(); } scanf("%d", &m); while (m--) { scanf("%s", word); query(); printf("%d\n", ans); } } void add(void) { node *cur = root; for (int i = 0; word[i] != '\0'; i++) { if ((cur -> son)[word[i] - 'a'] == nullptr) (cur -> son)[word[i] - 'a'] = new node; cur = (cur -> son)[word[i] - 'a']; (cur -> num)++; } } void query(void) { node *cur = root; for (int i = 0; word[i] != '\0'; i++) { if (cur -> son[word[i] - 'a'] == nullptr) { ans = 0; break; } cur = cur -> son[word[i] - 'a']; if (!word[i + 1]) { ans = cur -> num; } } }};int main(){ trie temp; temp.input(); return 0;}
0 0
- hihocoder 1014 Trie树 trie
- [hihoCoder 1014][Trie 树]Trie
- hihocoder 1014 trie树
- hihocoder#1014 : Trie树
- hihoCoder #1014 : Trie树
- [HiHoCoder]#1014 : Trie树
- hihoCoder#1014Trie树
- hihoCoder #1014 Trie树
- hihocoder-#1014 : Trie树
- hihoCoder 1014 : Trie树
- hihoCoder #1014 : Trie树
- hihocoder-#1014 : Trie树
- hihocoder #1014 trie 树
- hihoCoder - 1014 - Trie树
- hihoCoder 1014 Trie树
- hihocoder 1014 trie树
- HihoCoder 1014 : Trie树
- hihoCoder 1014Trie树
- Eclipse安装Freemarker插件
- TCP连接过程详解
- SparkSQL On Yarn with Hive,操作和访问Hive表
- ORCLE建表、增删改查
- xcopy拷贝所有文件
- hihocoder #1014 trie树
- PHP 将json的stdClass Object转成数组array 方法二
- js沙箱模式-内容摘自《javascript模式》
- python 新式类和旧式类
- html a onclick
- Mysql sql语句优化的10条建议
- ProgressBar使用自定义drawable时,进度显示不全的问题
- 最适合新手的 Markdown语法 使用指南
- Shader(着色器)类及其子类的使用