C - Oulipo
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 <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int Next[1100000];
char s1[1100000],s2[1100000];
void getnext(int l)
{
int i=0,j=-1;
Next[0]=-1;
while(i<l)
{
if(j==-1||s1[i]==s1[j])
{
i++,j++;
Next[i]=j;
}
else
j=Next[j];
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%s%s",s1,s2);
int l1=strlen(s1);
int l2=strlen(s2);
if(l1>l2)
{
printf("0\n");
continue;
}
getnext(l1);
int i=0,j=0,ans=0;
while(i<l2)
{
if(j==-1||s1[j]==s2[i])
{
i++,j++;
}
else j=Next[j];
if(j==l1)
{
j=Next[j];
ans++;
}
}
printf("%d\n",ans);
}
}
C - Oulipo的更多相关文章
- C++之路进阶——poj3461(Oulipo)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 35694 Accepted: 14424 Descript ...
- poj3461 Oulipo(KMP模板)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17795 Accepted: 7160 Descripti ...
- Match:Oulipo(POJ 3461)
Oulipo 题目大意:给你一个字符串,要你找到字符串包含指定子串的个数 只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧 #include < ...
- KMP算法 hdu4686 Oulipo
Problem Description The French author Georges Perec (1936–1982) once wrote a book, La disparition, w ...
- hdu----1686 Oulipo (ac自动机)
Oulipo Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Subm ...
- 字符串hash - POJ 3461 Oulipo
Oulipo Problem's Link ---------------------------------------------------------------------------- M ...
- POJ 3461 Oulipo
E - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ...
- Oulipo (kmp)
Oulipo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 26857 Accepted: 10709 Descript ...
- POJ 3461 Oulipo(乌力波)
POJ 3461 Oulipo(乌力波) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] The French autho ...
- A - Oulipo
A - Oulipo Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit S ...
随机推荐
- #3使用html+css+js制作网页 番外篇 使用python flask 框架 (II)
#3使用html+css+js制作网页 番外篇 使用python flask 框架 II第二部 0. 本系列教程 1. 登录功能准备 a.python中操控mysql b. 安装数据库 c.安装mys ...
- 【Redis3.0.x】数据类型
Redis3.0.x 数据类型 五大数据类型 String(字符串) string 是 redis 最基本的类型.可以理解成与 Memcached 一模一样的类型,一个 key 对应一个 value. ...
- 【C++】《C++ Primer 》第八章
第八章 IO库 一.IO类 1. 标准库定义的IO类型 头文件 作用 类型 iostream 从标准流中读写数据 istream, wistream 从流读取数据 ostream, wostream ...
- update 表名 set 某列名=now() where user in('user1','user2','user3');
update 表名 set 某列名=now() where user in('user1','user2','user3');
- 改进你的c#代码的5个技巧(四)
像每一篇文章一样,我会重复几行.我在我的Core i3 CPU.4GB主内存和Windows 7平台上测试了以下代码.如果你在不同的硬件配置或使用不同的平台,那么你的输出可能会随着我的输出屏幕而变化, ...
- 【Docker】/usr/bin/docker-current: Cannot connect to the Docker daemon at unix
------------------------------------------------------------------------------------------------- | ...
- C语言字符串结束符“\0”
介绍 '\0'就是8位的00000000,因为字符类型中并没有对应的这个字符,所以这么写.'\0'就是 字符串结束标志. '\0'是转译字符,意思是告诉编译器,这不是字符0,而是空字符.空字符\0对应 ...
- new String("ab")到底创建了几个对象说明
new String("ab")到底创建了几个对象? 之前一直被这个问题困扰,网上一些描述的都不是很清楚,自己看了一些资料可算搞清楚了,那就在博客上记录一下吧! String st ...
- 【源码解读】js原生消息提示插件
效果如下: 关闭message后前后message的衔接非常丝滑,这部分是我比较感兴趣的.带着这个问题先了解下DOM结构,顺便整理下作者的思路. 从DOM里我们可以看到所有的message都在一个容器 ...
- 权限管理3-整合Spring Security
一.Spring Security介绍 1.框架介绍 Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安 ...