[HDOJ 1251] 统计难题 [字典树]
2014-05-03 23:32
375 查看
裸题...
#include <cstdio> #include <cstring> using namespace std; const int N=500000; struct Node { Node *ch[26]; int num; }; Node a ; Node *root; char s[11]; int p=0; Node *newNode() { memset(a[p].ch,0,sizeof(a[p].ch)); a[p].num=0; return &a[p++]; } void insert(char *s) { Node *cur=root; cur->num++; while (*s!='\0') { int t=*(s++)-'a'; if (cur->ch[t]==NULL) cur->ch[t]=newNode(); cur=cur->ch[t]; cur->num++; } } int getans(char *s) { Node *cur=root; while (*s!='\0') { int t=*(s++)-'a'; if (cur->ch[t]==NULL) return 0; cur=cur->ch[t]; } return cur->num; } int main() { root=newNode(); gets(s); while (s[0]!='\0') { insert(s); gets(s); } while (scanf("%s",s)!=EOF) { printf("%d\n",getans(s)); } return 0; }
相关文章推荐
- HDOJ 1251 统计难题(j简单的字典树trie的应用)
- HDOJ1251 统计难题(字典树)
- hdoj 1251 统计难题 【STL map+string】 【字典树基础题】
- HDOJ 题目1251统计难题(字典树,模板)
- HDOJ 1251 统计难题 (字典树)
- hdoj-1251-统计难题(字典树)
- HDOJ 1251-统计难题【模板:字典树】
- HDOJ 1251 统计难题(字典树)
- [字典树入门] HDOJ 1251 统计难题
- hdoj-1251 统计难题(字典树)
- HDOJ 1251 统计难题(map or 字典树)
- HDOJ 1251 统计难题——第二次用字典树AC题目,写一下解题报告
- 入门字典树 HDOJ1251 统计难题 HDOJ1075 字典翻译
- HDOJ-1251 统计难题 字典树的应用-----统计一组字符串中某前缀出现次数(字典树第一类应用),
- hdoj1251 统计难题 字典树
- hdoj 1251 统计难题 【字典树】
- hdoj 1251 统计难题(经典字典树)
- hdoj 1251 统计难题《字典树》
- hdoj 1251 统计难题【字典树 基础题】
- HDOJ 1251 统计难题 字典树