Language: C++

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#define INF 100005
using namesapce std;
char str[INF];
struct acnode{
	int sum;
	ancode *next[26];
	ancode *fail;
	ancode():sum(0),fail(NULL){
		for(int i=0;i<26;i++){
			next[i]=NULL;
		}
	}
}root;
void insrt(char *s){
	int len=strlen(s);
	ancode *p=&root;
	for(int i=0;i<len;++i){
		if(p->next[s[i]-'a']==NULL){
			ancode *te=new ancode();
			p->next[s[i]-'a']=te;
		}
		p->next[s[i]-'a'];
	}
	p->sun++;
}
void getfail(){
	ancode *p=&root;
	queue<ancode*> que;
	for(int i=0;i<26;i++){
		if(p->next[i]!=NULL){
			p->next[i]->fail=p;
			que.push(p->next[i]);
		}
		while(!que.empty()){
			ancode *h=que.front();
			for(int i=0;i<26;i++){
				if(h->next[i]!=NULL){
					ancode *te=h->fail;
					while(te!=NULL){
						if(te->next[i]!=NULL){
							h->next[i]->fail=te->next[i];
							break;
						}
						else{
							te=te->fail;
						}
						if(te==NULL)
							h->next[i]->fail=&root;
							que.push(h->next[i]);
					}
				}
				que.pop();
			}
		}
	} 
}
int srarch(char *s){
	int ans=0;
	ancode *p=&root;
	for(int i=0;s[i];){
		if(p->next[s[i]-'a']!=NULL){
			ancode *te=p->next[s[i]-'a'];
			while(te!=&root){
				if(te->sum)
					ans+=te->sum;
					te=te->fail; 
			}
			p=p->next[s[i++]-'a'];
		}
		else{
			if(p->fail==NULL)
				i++;
			else
			{
				p=p->fail;
			}
		}
		return ans;
	}
}
void acclear(ancode *p){
	for(int u=0;i<26;i++){
		if(p->next[i]!=NULL){
			acclear(p->next[i]);
			if(p!=&root)
			free(p);
			else
			root=ancode();
		}
	}
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%s",str);
			insrt(str);
		}
		getfail();
		scanf("%s",str);
		printf("%d\n",search(str));
		accelar(&root);
	}
}


Compiler output:
a.cc:6:7: error: expected nested-name-specifier before 'namesapce'
    6 | using namesapce std;
      |       ^~~~~~~~~
a.cc:10:9: error: 'ancode' does not name a type; did you mean 'acnode'?
   10 |         ancode *next[26];
      |         ^~~~~~
      |         acnode
a.cc:11:9: error: 'ancode' does not name a type; did you mean 'acnode'?
   11 |         ancode *fail;
      |         ^~~~~~
      |         acnode
a.cc:12:9: error: ISO C++ forbids declaration of 'ancode' with no type [-fpermissive]
   12 |         ancode():sum(0),fail(NULL){
      |         ^~~~~~
a.cc: In member function 'int acnode::ancode()':
a.cc:12:18: error: only constructors take member initializers
   12 |         ancode():sum(0),fail(NULL){
      |                  ^~~
a.cc:12:25: error: class 'acnode' does not have any field named 'fail'
   12 |         ancode():sum(0),fail(NULL){
      |                         ^~~~
a.cc:14:25: error: 'next' was not declared in this scope; did you mean 'std::next'?
   14 |                         next[i]=NULL;
      |                         ^~~~
      |                         std::next
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: 'std::next' declared here
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:16:9: warning: no return statement in function returning non-void [-Wreturn-type]
   16 |         }
      |         ^
a.cc: In function 'void insrt(char*)':
a.cc:20:9: error: 'ancode' was not declared in this scope; did you mean 'acnode'?
   20 |         ancode *p=&root;
      |         ^~~~~~
      |         acnode
a.cc:20:17: error: 'p' was not declared in this scope
   20 |         ancode *p=&root;
      |                 ^
a.cc:23:33: error: 'te' was not declared in this scope; did you mean 'tm'?
   23 |                         ancode *te=new ancode();
      |                                 ^~
      |                                 tm
a.cc:23:40: error: expected type-specifier before 'ancode'
   23 |                         ancode *te=new ancode();
      |                                        ^~~~~~
a.cc: In function 'void getfail()':
a.cc:31:9: error: 'ancode' was not declared in this scope; did you mean 'acnode'?
   31 |         ancode *p=&root;
      |         ^~~~~~
      |         acnode
a.cc:31:17: error: 'p' was not declared in this scope
   31 |         ancode *p=&root;
      |                 ^
a.cc:32:9: error: 'queue' was not declared in this scope; did you mean 'std::queue'?
   32 |         queue<ancode*> que;
      |         ^~~~~
      |         std::queue
In file included from /usr/include/c++/14/queue:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_queue.h:96:11: note: 'std::queue' declared here
   96 |     class queue
      |           ^~~~~
a.cc:32:22: error: expected primary-expression before '>' token
   32 |         queue<ancode*> que;
      |                      ^
a.cc:32:24: error: 'que' was not declared in this scope
   32 |         queue<ancode*> que;
      |                        ^~~
a.cc:39:33: error: 'h' was not declared in this scope
   39 |                         ancode *h=que.front();
      |                                 ^
a.cc:42:49: error: 'te' was not declared in this scope; did you mean 'tm'?
   42 |                                         ancode *te=h->fail;
      |                                                 ^~
      |                                                 tm
a.cc: In function 'int srarch(char*)':
a.cc:63:9: error: 'ancode' was not declared in this scope; did you mean 'acnode'?
   63 |         ancode *p=&root;
      |         ^~~~~~
      |         acnode
a.cc:63:17: error: 'p' was not declared in this scope
   63 |         ancode *p=&root;
      |                 ^
a.cc:66:33: error: 'te' was not declared in this scope; did you mean 'tm'?
   66 |                         ancode *te=p->next[s[i]-'a'];
      |                                 ^~
      |                                 tm
a.cc: At global scope:
a.cc:85:6: error: variable or field 'acclear' declared void
   85 | void acclear(ancode *p){
      |      ^~~~~~~
a.cc:85:14: error: 'ancode' was not declared in this scope; did you mean 'acnode'?
   85 | void acclear(ancode *p){
      |              ^~~~~~
      |              acnode
a.cc:85:22: error: 'p' was not declared in this scope
   85 | void acclear(ancode *p){
      |                      ^
a.cc: In function 'int main()':
a.cc:108:31: error: 'search' was not declared in this scope; did you mean 'std::search'?
  108 |                 printf("%d\n",search(str));
      |                               ^~~~~~
      |                               std::search
In file included from /usr/include/c++/14/string:51:
/usr/include/c++/14/bits/stl_algobase.h:2332:5: note: 'std::search' declared here
 2332 |     search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
      |     ^~~~~~
a.cc:109:17: error: 'accelar' was not declared in this scope
  109 |                 accelar(&root);
      |                 ^~~~~~~
a.cc: In function 'int srarch(char*)':
a.cc:84:1: warning: control reaches end of non-void function [-Wreturn-type]
   84 | }
      | ^