RepositoryTime
limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 3247 Accepted Submission (s): 1227
Problem Descriptionwhen You go shopping, you can search in repository for avalible merchandises by the computers and Inter Net. First you give the search system a name is about something and then the system responds with the results. Now is given a lot merchandise names on repository and some queries, and required to simulate the process.
Inputthere is the only one case. First there is a integer P (1<=p<=10000) representing the number of the Merchanidse names in the repository. The next P lines each contain a string (it's length isn ' t beyond 20,and all the letters is lowercase). Then there was an integer Q (1<=q<=100000) representing the number of the queries. The next Q lines each contains a string (the same limitation as foregoing descriptions) as the searching condition.
Outputfor each query, you just output the number of the merchandises, whose names contain the search string as their subst Rings.
Sample Input
20adaeafagahaiajakaladsaddadeadfadgadhadiadjadkadlaes5badads
Sample Output
02011112
Source2009 multi-university Training Contest 4-host by HDU
/*http://acm.hdu.edu.cn/showproblem.php?pid=2846repository Dictionary Tree variable */#include <stdio.h> #include <stdlib.h > #include <string.h> #include <string> #include <iostream>using namespace std;typedef struct node{ int No;int count;struct node* next[27];node (int _count = 0) {count = _count;no = -1;int i;for (i = 0; i <; i + +) {NEX T[i] = NULL;}}} Trie;void Insertnode (trie* Trie, char* s,int noo) {trie* T = trie;int i = 0;while (s[i]! = ' + ') {int tmp = s[i]-' a '; if (T-&G T;NEXT[TMP] = = NULL) {t->next[tmp] = new node (0);} t = t->next[tmp];if (t->no! = noo)//noo do tag increase number {T->count ++;t->no = Noo;} i + +;}} int func (trie* Trie,char s[]) {trie* t = Trie; trie* Tpre;int i = 0;while (s[i]! = ' + ') {int tmp = s[i]-' a '; if (t->next[tmp] = = NULL) {return 0;} Tpre = T;t = T->next[tmp];i + +;} return t->count;} int main () {//freopen ("In.txt", "R", stdin); int n, m; int i, J; scanf ("%d", &n); char stmp[21]; trie* Trie = new node (0), for (i = 0; i < n; i + +) {scanf ("%s", stmp);T len = strlen (STMP);/* here for stmp = "abc" is divided into abc,bc,c these 3 strings are inserted once after inserting as root/| A b c/| b/C Each time this processing, the corresponding character count will be added to the end of the statistics count on the line */for (j = 0;j < Len; j + +) {Insertnode (trie, stmp+j, i);}} scanf ("%d", &m), for (i = 0; i < m; i + +) {scanf ("%s", stmp);p rintf ("%d\n", Func (Trie,stmp));} return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2846 Repository-Dictionary tree