HDU
来源:互联网 发布:三体读后感知乎 编辑:程序博客网 时间:2024/06/09 14:35
字典树模板题
G++ Memory Limit Exceeded
C++ Accepted
#include<stdio.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<iostream>using namespace std;struct node{int num;node *next[26];node(){num=0;for(int i=0;i<26;i++)next[i]=NULL;}};node *root=new node;node *head,*tail;void update(char *s){int i,m;head=root;for(i=0;i<strlen(s);i++){m=s[i]-'a';if(head->next[m]!=NULL){head=head->next[m];++(head->num);}else{tail=new node;++(tail->num);head->next[m]=tail;head=tail;}}}int query(char *s){int i,m;head=root;for(i=0;i<strlen(s);i++){m=s[i]-'a';if(head->next[m]==NULL)return 0;head=head->next[m];}return head->num;}int main(void){int i,j,k,n,m;char s[20];while(gets(s),strcmp(s,""))update(s);while(gets(s)!=NULL)printf("%d\n",query(s));return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 算术表达式补全右括号(algs4)
- JavaScript 数据类型篇
- set的底层实现
- TCP、UDP以及HTTP的简单讲解
- Centos下安装Mysql 官网教程-便捷快速
- HDU
- @property 后面都有哪些修饰符
- jav基础
- 与第三方对接web service的坑
- HDU 6097 Mindis 代数方法
- CGI、FastCGI、WSGI
- php limit m,n 用法
- 剑指offer——二叉树的下一个节点
- 设计模式之创建型模式(1)--单例模式