G++超内存
G++超内存
G++超内存
banana band bee absolute acm ba b band abc
2 3 1 0
#pragma warning(disable:4786)//使命名长度不受限制 #pragma comment(linker, "/STACK:102400000,102400000")//手工开栈 #include <map> #include <set> #include <queue> #include <cmath> #include <stack> #include <cctype> #include <cstdio> #include <cstring> #include <stdlib.h> #include <iostream> #include <algorithm> #define rd(x) scanf("%d",&x) #define rd2(x,y) scanf("%d%d",&x,&y) #define rds(x) scanf("%s",x) #define rdc(x) scanf("%c",&x) #define ll long long int #define maxn 100005 #define mod 1000000007 #define INF 0x3f3f3f3f //int 最大值 #define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i) #define MT(x,i) memset(x,i,sizeof(x)) #define PI acos(-1.0) #define E exp(1) #define MAX 26 using namespace std; struct Trie{ Trie *next[MAX]; int v; }; Trie root; void createTrie(char *str){ int len=strlen(str); Trie *p=&root,*q; FOR(i,0,len-1){ int id=str[i]-'a'; if(p->next[id]==NULL){ q=(Trie *)malloc(sizeof(Trie)); q->v=1; FOR(j,0,MAX-1) q->next[j]=NULL; p->next[id]=q; p=p->next[id]; } else { p->next[id]->v++; p=p->next[id]; } } //p->v=1; } int find_Trie(char *str){ int len=strlen(str); Trie *p=&root; FOR(i,0,len-1){ int id=str[i]-'a'; if(p->next[id]==NULL) return 0; p=p->next[id]; } return p->v; } int main(){ char str[11]; FOR(i,0,MAX-1) root.next[i]=NULL; while(gets(str)&&str[0]!='\0') createTrie(str); while(rds(str)!=EOF) printf("%d\n",find_Trie(str)); return 0; } /* banana band bee absolute acm ba b band abc */