hdu1247
来源:互联网 发布:软件外包qq群 编辑:程序博客网 时间:2024/05/16 10:44
/*
数组竟然才开5000?!!!WA了4次并且WA了快两天都没有发现?!!!
第一次就开对,就1a了!!!
2012-07-05
*/
分析:
感谢Lelouch的帮忙O(∩_∩)O~
另外……
ac后,我最想说的是……:我……靠!!!数组竟然才开5000?!!!WA了4次并且WA了快两天都没有发现?!!!
第一次就开对,就1a了!!!
- - 再犯这种低级错误,这条道儿……就不用混了……
很easy的字典树,就不废话了
2012-07-05
*/
#include"stdio.h"#include"stdlib.h"#include"string.h"struct dictree{struct dictree *child[26];int flag;};struct dictree *root;char str[50011][50];void insert(char *source){int i,j;int len;struct dictree *current,*newnode;len=strlen(source);current=root;for(i=0;i<len;i++){if(current->child[source[i]-'a']!=0)current=current->child[source[i]-'a'];else{newnode=(struct dictree *)malloc(sizeof(struct dictree));for(j=0;j<26;j++)newnode->child[j]=0;newnode->flag=0;current->child[source[i]-'a']=newnode;current=newnode;}}current->flag=1;}int find(char *source){int i;int len;struct dictree *current;len=strlen(source);current=root;for(i=0;i<len;i++){if(current->child[source[i]-'a']!=0)current=current->child[source[i]-'a'];elsereturn 0;}return current->flag;}int main(){char t1[50],t2[50];int t;int k;int i,l,j,j2;int len;int hash[50011];root=(struct dictree *)malloc(sizeof(struct dictree));for(j=0;j<26;j++)root->child[j]=0;root->flag=0;k=0;while(scanf("%s",str[k])!=-1){insert(str[k]);k++;}for(i=0;i<k;i++){len=strlen(str[i]);hash[i]=0;if(len==1)continue;t=len-1;for(l=1;l<=t;l++){for(j=0;j<l;j++)t1[j]=str[i][j];t1[j]=0;for(j2=0;j<len;j++,j2++)t2[j2]=str[i][j];t2[j2]=0;if(find(t1)&&find(t2)){hash[i]=1;break;}}}for(i=0;i<k;i++)if(hash[i])printf("%s\n",str[i]);return 0;}
- hdu1247
- hdu1247
- hdu1247
- hdu1247
- hdu1247
- HDU1247字典树
- hdu1247 字典树模板
- hdu1247 Hat’s Words
- HDU1247(字典树)
- HDU1247 字典树
- HDU1247 Hat’s Words
- hdu1247字典树
- hdu1247 Hat’s Words
- hdu1247字典树
- hdu1247(trie树)
- hdu1247 hat's words
- hdu1247 Hat’s Words
- hdu1247 Hat’s Words
- 获得目录文件数和剩余容量的dos命令
- 安卓学习
- Linux查看文件夹大小及统计总数等
- gpio linux 实现模型
- const与引用
- hdu1247
- ls命令只显示文件而不显示目录
- 路由器级联
- json-default
- Android Wifi BT的工作流程和porting(精)
- java中的clone技术
- 基本数据类型
- jqmobile如何使用flip效果(翻书效果)
- zi dong fa tie ji