首页 > 其他 > 详细

字典树 HDU 1251 统计难题

时间:2015-07-31 09:01:03      阅读:207      评论:0      收藏:0      [点我收藏+]
http://acm.hdu.edu.cn/showproblem.php?pid=1251

#include<iostream> #include<algorithm> #include<stdio.h>
using namespace std; struct node { int sum; node *next[26]; }; void buildtrietree(node *head, char s[]) { node *p=new node(); p=head; for(int i=0; s[i]; i++) { int k=s[i]-‘a‘; if(p->next[k]==0) p->next[k]=new node(); p=p->next[k]; p->sum++; } } int query(node *head, char s[]) { node *p=new node(); p=head; for(int i=0; s[i]; i++) { int k=s[i]-‘a‘; if(p->next[k]==0) return 0; p=p->next[k]; } return p->sum; } int main() { char s[12]; node *head=new node(); while(gets(s), s[0]) buildtrietree(head, s); while(cin >> s) printf("%d\n", query(head, s)); return 0; }

 

字典树 HDU 1251 统计难题

原文:http://www.cnblogs.com/wazqWAZQ1/p/4691142.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!