The French author Georges Perec (1936�C1982) once wrote a book, La disparition, without the letter 'e'. He was a member of the Oulipo group. A quote from the book:

Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair normal, d’abord, puis surgissait l’inhumain, l’affolant. Il aurait voulu savoir où s’articulait l’association qui l’unissait au roman : stir son tapis, assaillant à tout instant son imagination, l’intuition d’un tabou, la vision d’un mal obscur, d’un quoi vacant, d’un non-dit : la vision, l’avision d’un oubli commandant tout, où s’abolissait la raison : tout avait l’air normal mais…

Perec would probably have scored high (or rather, low) in the following contest. People are asked to write a perhaps even meaningful text on some subject with as few occurrences of a given “word” as possible. Our task is to provide the jury with a program that counts these occurrences, in order to obtain a ranking of the competitors. These competitors often write very long texts with nonsense meaning; a sequence of 500,000 consecutive 'T's is not unusual. And they never use spaces.

So we want to quickly find out how often a word, i.e., a given string, occurs in a text. More formally: given the alphabet {'A', 'B', 'C', …, 'Z'} and two finite strings over that alphabet, a word W and a text T, count the number of occurrences of W in T. All the consecutive characters of W must exactly match consecutive characters of T. Occurrences may overlap.

InputThe first line of the input file contains a single number: the number of test cases to follow. Each test case has the following format:

One line with the word W, a string over {'A', 'B', 'C', …, 'Z'}, with 1 ≤ |W| ≤ 10,000 (here |W| denotes the length of the string W). 
One line with the text T, a string over {'A', 'B', 'C', …, 'Z'}, with |W| ≤ |T| ≤ 1,000,000. 
OutputFor every test case in the input file, the output should contain a single number, on a single line: the number of occurrences of the word W in the text T.

Sample Input

3
BAPC
BAPC
AZA
AZAZAZA
VERDI
AVERDXIVYERDIAN

Sample Output

1
3
0
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
using namespace std;
#define MAXN 1000001
typedef long long LL;
/*
KMP 查找子串出现的次数
*/
char s[MAXN],t[MAXN];
int Next[MAXN];
void pre_kmp(int m)
{
int j,k;
j = ;k = -;Next[] = -;
while(j<m)
if(k==-||t[k]==t[j])
Next[++j] = ++k;
else
k = Next[k];
}
int KMP(char s[],char t[],int n,int m)
{
int i,j,ans;
i = j = ans = ;
if(n==&&m==)
return (s[]==t[])?:;
pre_kmp(m);
for(i=;i<n;i++)
{
while(j>&&s[i]!=t[j])
j = Next[j];
if(s[i]==t[j])
j++;
if(j==m)
{
ans++;
j = Next[j];
}
}
return ans;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%s%s",t,s);
printf("%d\n",KMP(s,t,strlen(s),strlen(t)));
}
}

B - Oulipo的更多相关文章

  1. C++之路进阶——poj3461(Oulipo)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35694   Accepted: 14424 Descript ...

  2. poj3461 Oulipo(KMP模板)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17795   Accepted: 7160 Descripti ...

  3. Match:Oulipo(POJ 3461)

     Oulipo 题目大意:给你一个字符串,要你找到字符串包含指定子串的个数 只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧 #include < ...

  4. KMP算法 hdu4686 Oulipo

    Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...

  5. hdu----1686 Oulipo (ac自动机)

    Oulipo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  6. 字符串hash - POJ 3461 Oulipo

    Oulipo Problem's Link ---------------------------------------------------------------------------- M ...

  7. POJ 3461 Oulipo

      E - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit ...

  8. Oulipo (kmp)

    Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 26857   Accepted: 10709 Descript ...

  9. POJ 3461 Oulipo(乌力波)

    POJ 3461 Oulipo(乌力波) Time Limit: 1000MS   Memory Limit: 65536K [Description] [题目描述] The French autho ...

  10. A - Oulipo

    A - Oulipo Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

随机推荐

  1. 图练习-BFS-从起点到目标点的最短步数

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2830 简单bfs #include <s ...

  2. [Apple开发者帐户帮助]九、参考(1)证书类型

    该证书类型有助于开发者帐户和Xcode的标识证书. 类型 目的 APNs Auth Key 生成服务器端令牌,以替代通知请求的证书. Apple推送服务 在通知服务和APN之间建立连接,以向您的应用提 ...

  3. [Swift通天遁地]七、数据与安全-(9)文件的压缩和解压

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  4. 常见的Java Script内存泄露原因及解决方案

    前言 内存泄漏指由于疏忽或错误造成程序未能释放已经不再使用的内存.内存泄漏并非指内存在物理上的消失,而是应用程序分配某段内存后,由于设计错误,导致在释放该段内存之前就失去了对该段内存的控制,从而造成了 ...

  5. BZOJ 2178 Simpson积分

    思路: 我发现能用Simpson积分水的题  好像都是裸题诶233333 //By SiriusRen #include <bits/stdc++.h> using namespace s ...

  6. 记一次Oracle冷备恢复的过程

    一.故障来临 某日中午,市电意外中断,机房UPS电源由于负载过重而未接管供电,所有服务器全部重启...... 待所有服务器重启后,正在逐一检查设备和业务运行情况时,意外发生了.一台年代久远的HP PC ...

  7. Storm 入门一:基本知识+网上资源链接

    Strom首页:http://storm.apache.org/ 下载地址:http://www.apache.org/dyn/closer.lua/storm/apache-storm-1.1.0/ ...

  8. windows phone 8 使用页面传对象的方式 实现页面间的多值传递

    在做windows phone 开发的时候,会经常碰到页面间之间的跳转和传递数据,如果传递的值不多,只有两三个,我们通常使用NavigationService.Navigate(new Uri(&qu ...

  9. 扩增子图表解读1箱线图:Alpha多样性

    箱线图 箱形图(Box-plot)又称为盒须图.盒式图或箱线图,是一种用作显示一组数据分散情况资料的统计图.因形状如箱子而得名.在宏基因组领域,常用于展示样品组中各样品Alpha多样性的分布 第一种情 ...

  10. PHP控制反转(IOC)和依赖注入(DI

    <?php class A { public $b; public $c; public function A() { //TODO } public function Method() { $ ...