hihocoder 1014: Trie树(Trie树模板题)
2017-02-27 19:59
423 查看
题目链接
View Code
#include<bits/stdc++.h> using namespace std; const int L=12; struct T { int num; T* next[26]; T() { num=0; int i; for(int i=0;i<26;i++) next[i]=NULL; } }t; void insert(char str[]) { T* p=&t; for(int i=0;str[i];i++) { int a=str[i]-'a'; if(p->next[a]==NULL) p->next[a]=new T; p=p->next[a]; p->num++; } } int find(char str[]) { T* p=&t; for(int i=0;str[i];i++) { int a=str[i]-'a'; if(p->next[a]==NULL) return 0; p=p->next[a]; } return p->num; } int main() { int n,m; char str[L]; scanf("%d",&n); while(n--) scanf("%s",str),insert(str); scanf("%d",&m); while(m--) scanf("%s",str),printf("%d\n",find(str)); }
View Code
相关文章推荐
- Hihocoder 1014Trie树(字典树模板)
- hihoCoder 1014 Trie树 字典树模板
- hihocoder 1014 Trie树 (Trie 记模板 数组+指针)
- hihocoder_1014: Trie树(Trie树模板题)
- hihoCoder #1014 : Trie树
- solution of hihoCoder #1014 : Trie树
- hihoCoder 1014 Trie树 (Trie)
- Hihocoder1014 Tire前缀树 很好的模板
- hihoCoder 1014 : Trie树
- hihoCoder 1014 Trie树
- hihoCoder 1014 Trie树
- hihoCoder--1014 Trie树
- hihocoder1014 Trie树
- hihocoder 1014 Trie树 字典树
- HihoCoder 1014 : Trie树
- hihoCoder 1014 Trie树
- hihoCoder - 1014 : Trie树 - (字典树)
- hihoCoder 1014 Trie树(字典树入门)
- hihocoder 1014 Trie树
- hihoCoder 1014 Trie树