Oulipo |
Time Limit: 5000ms, Special Time Limit:12500ms, Memory Limit:65536KB |
Problem description |
The French author Georges Perec (1938-1982) once wrote a book, La disparition, without the letter ‘e’. He was a member of Oulipo group. A quote from the book: Tout avait l’air normal, mais tout s’affirmait faux. Tout avait l’air normal, d’abord, puis surgissait l’inhumain, l’affolant.Ⅱaurait voulu savoir ou s, articulait l’association qui l’unissait au roman: sur son tapis, assailant atout instant son imagination, l’intution d’un tabou, la vision d’un mal obscure, d’sun quoi vacant, d’un non-dit: la vision, l’avision d’un oubli commandant tout,ou 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 the cases to follow. Each test case has 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 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 |
3 BAPC BAPC AZA AZAZAZA VERDI AVERDXIVYERDIAN |
Sample Output |
1 3 0 /// 解题报告 本题的较好的做法是:在子串的末尾虚设一字符(并不需要真的去设置 不过还是发了1078ms,不知道他们那些XXms的是怎样做的,以后搞到代码了 //mycode as followed: #include <stdio.h> // 获取KMP匹配时串 str 的 next 表,另外求了虚设字符的 next 值 // 获取gDest在gStr中的出现次数 int main(){ //// 这样就优化了,速度竟快了十几倍 !!! #include <stdio.h> void getNext(){ int getCount(){ int main(){ |
正文
Oulipo (模式匹配)2007-10-08 07:46:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/lingdlz/29948.html
阅读(2933) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论