#include <bits/stdc++.h>

 using namespace std;

 const int N = *;
const int M = ; map<string,int>Map;
struct Trie
{
int next[N][M],fail[N],end[N];
int root,L;
int newnode()
{
for(int i = ; i < ; i++)
next[L][i] = -;
end[L++] = -;
return L - ;
}
void init()
{
L = ;
root = newnode();
}
void insert(string s,int id)
{
int len = s.size();
int now = root;
for(int i = ; i < len; i++)
{
if(next[now][s[i]-'a'] == -)
next[now][s[i] - 'a'] = newnode();
now = next[now][s[i] - 'a'];
}
end[now] = id;
}
void build()
{
queue<int>Q;
fail[root] = root;
for(int i = ; i < ; i++)
{
if(next[root][i] == -)
next[root][i] = root;
else
{
fail[next[root][i]] = root;
Q.push(next[root][i]);
}
}
while(!Q.empty())
{
int now = Q.front();
Q.pop();
for(int i = ; i < ; i++)
{
if(next[now][i] == -)
next[now][i] = next[fail[now]][i];
else
{
fail[next[now][i]] = next[fail[now]][i];
Q.push(next[now][i]);
}
}
}
}
int num[];
void query(char buf[],int n,int mm[])
{
for(int i = ; i <= n; i++)
num[i] = ;
int len = (int)strlen(buf);
int now = root;
for(int i = ; i < len; i++)
{
now = next[now][buf[i]-'a'];
int temp = now;
while( temp != root )
{
if( end[temp] != -)
num[end[temp]]++;
temp = fail[temp];
}
}
for(int i = ; i <= n; i++)
printf("%d\n",num[mm[i]]);
}
}; char buf[];
Trie ac; void solve()
{
ac.init();
int n, l = ;
scanf("%d",&n);
scanf("%s",buf);
Map.clear();
int twice[];
memset(twice,,sizeof(twice));
for(int i = ; i <= n; i++)
{
string ss;
cin>>ss;
int c = Map[ss];
if(c == )
{
Map[ss] = ++l;
ac.insert(ss,l);
}
twice[i] = Map[ss];
//int tmp = Map[ss]; }
ac.build(); ac.query(buf,n,twice);
} int main(void)
{
int t,cnt = ;
scanf("%d",&t);
while(t--)
{
printf("Case %d:\n",++cnt);
solve();
} return ;
}

最新文章

  1. Xamarin体验:使用C#开发iOS/Android应用
  2. C#定时任务组件之FluentScheduler
  3. 有shi以来最详细的正则表达式入门教程
  4. Linux shell程序一
  5. curl毫秒超时使用的坑
  6. Java中的Set, List, Map漫谈
  7. Quirks模式是什么?
  8. Git@OSC &amp; SSH配置
  9. 转:sql SELECT时的with(nolock)选项说明
  10. HDU 4006 The kth great number 优先队列、平衡树模板题(SBT)
  11. FrameBuffer系列 之 介绍
  12. .NET接入接口/请求服务器
  13. 将python2代码转为python3
  14. (摘)使用 .NET Core 实现依赖关系注入
  15. [转]linux下编译boost.python
  16. .Net MVC TextBoxFor 扩展 placeholder 与 class 属性
  17. 关于MySQL中添加数据的两种方法
  18. JMeter学习(三十四)使用jmeter来发送json/gzip格式数据(转载)
  19. openstack(Pike 版)集群部署(五)--- Neutron 部署
  20. Selenium WebDriver VS Selenium RC

热门文章

  1. reg命令详解
  2. LeetCode第一题—— Two Sum(寻找两数,要求和为target)
  3. 使用Cookie实现用户商品历史浏览记录
  4. duilib教程之duilib入门简明教程3.第一个程序 Hello World
  5. 【BZOJ 1257】[CQOI2007]余数之和sum
  6. python中的多线程编程与暂停、播放音频的结合
  7. Java笔记 - 线程与并行API
  8. express 4 使用session和cookies
  9. mysql80版本—yum安装—图文全过程
  10. 启动zuul时候报错:The bean &#39;proxyRequestHelper&#39;, defined in class path resource [org/springframework/cloud/netflix/zuul