博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【POJ3461】Olipo
阅读量:5302 次
发布时间:2019-06-14

本文共 2484 字,大约阅读时间需要 8 分钟。

Description

The French author Georges Perec (1936–1982) 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.

Input

The 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.

Output

For 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

3BAPCBAPCAZAAZAZAZAVERDIAVERDXIVYERDIAN

Sample Output

130

Source

题意:看样例。
KMP模板,程序模拟+手动模拟大概是明白了一些。
1 #include 
2 #include
3 #include
4 5 using namespace std; 6 7 char A[1000000+10],B[1000000+10]; 8 int T[1000000+10]; 9 int n,ans;10 11 void calc_T()//找到失配函数12 {13 T[0]=-1;14 int j,lenA=strlen(A);15 for (int i=0;i
Code

 

转载于:https://www.cnblogs.com/DMoon/p/5198539.html

你可能感兴趣的文章
BlackBerry Localization sample (1)
查看>>
Remainder
查看>>
Android:pressed状态下,改变背景和Text样式
查看>>
Spring层次图
查看>>
Unity3D学习笔记(三十一):Xlua(1)
查看>>
第一个C程序 (Blog测试)
查看>>
第一次实验报告
查看>>
删除文本文件行号的小方法(shell,sed)
查看>>
Boyer-Moore字符串查找算法的实现
查看>>
pandas.to_datetime() 只保留【年-月-日】
查看>>
org.apache.flume.FlumeException: NettyAvroRpcClient { host: xxx.xxx.xxx.xxx, port: 41100 }: RPC
查看>>
Composer学习之————Ubuntu14.04下安装Composer
查看>>
WorkerMan 入门学习之(三)基础教程-Timer类的使用
查看>>
pthreads 2.0.10 test
查看>>
iOS不显示状态栏(电池和信号栏)
查看>>
整理LVS架构压力测试工作
查看>>
信息安全导论-密码技术部分-读书笔记-1
查看>>
读书笔记-操作系统教程- 处理机管理-2
查看>>
判断回文联
查看>>
【转】什么是编码?
查看>>