Oulipo

  题目大意:给你一个字符串,要你找到字符串包含指定子串的个数

  只要你知道了KMP,这一题简直不要太简单,注意STL的string是会超时的,还是乖乖用char吧

  

 #include <iostream>
#include <algorithm>
#include <functional>
#include <string.h> using namespace std; typedef int Position;
static char Text[], Word[];
static int Next[]; void KmpSearch(const int, const int);
void GetNext(const int); int main(void)
{
int case_sum;
scanf("%d", &case_sum);
getchar(); while (case_sum--)
{
scanf("%s", Word);
scanf("%s", Text);
KmpSearch(strlen(Word), strlen(Text));
}
return EXIT_SUCCESS;
} void KmpSearch(const int w_len, const int t_len)
{
Position i = , j = ;
int k_count = ;
GetNext(w_len); while (i < t_len)
{
if (j == - || Text[i] == Word[j])
{
i++;
j++;
if (j == w_len)
{
k_count++;
j = Next[j];
}
}
else j = Next[j];
}
printf("%d\n", k_count);
} void GetNext(const int w_len)
{
Position i = , k = -;
Next[] = -; while (i < w_len)
{
if (k == - || Word[i] == Word[k])
{
i++;
k++;
Next[i] = Word[i] != Word[k] ? k : Next[k];
}
else k = Next[k];
}
}

  

Match:Oulipo(POJ 3461)的更多相关文章

  1. HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)

    HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...

  2. (KMP)Oulipo -- poj --3461

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=92486#problem/B http://poj.org/problem?id=3461 ...

  3. AC日记——Oulipo poj 3461

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37958   Accepted: 15282 Description The ...

  4. Oulipo POJ - 3461(kmp,求重叠匹配个数)

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

  5. POJ 3461 Oulipo

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

  6. POJ 3461 Oulipo(乌力波)

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

  7. POJ 3461 Oulipo[附KMP算法详细流程讲解]

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

  8. POJ 3461 Oulipo 【KMP统计子串数】

    传送门:http://poj.org/problem?id=3461 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submission ...

  9. poj 3461 Oulipo,裸kmp

    传送门 Oulipo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32373   Accepted: 13093 Desc ...

随机推荐

  1. ubuntu用apt-get安装memcache

    转自:http://yangfutao2000.blog.163.com/blog/static/12162588201151635856858/ 先安装服务器端: apt-get install m ...

  2. java.lang.reflect.Method

    java.lang.reflect.Method 一.Method类是什么 Method是一个类,位于java.lang.reflect包下. 在Java反射中 Method类描述的是 类的方法信息, ...

  3. 利用CSS实现带相同间隔地无缝滚动动画

    说明:因为在移动上主要利用CSS来做动画,所以没有考虑其他浏览器的兼容性,只有-webkit这个前缀,如果需要其他浏览器,请自行补齐. 首先解释一下什么是无缝滚动动画, 例如下面的例子 See the ...

  4. 一个简单的猜大小的小游戏 python

    初学python,用python写了一个简单的猜大小的小游戏 #!/usr/bin/env python #-*- coding:utf-8 -*- print "------------- ...

  5. corntab

    http://www.cnblogs.com/peida/archive/2013/01/08/2850483.html

  6. 遇到了IAR烧写程序出错,附解决办法The stack plug-in failed to set a breakpoint on "main"

    今天做无线串口调试的时候用IAR7.51往CC2530无线模块烧程序的时候遇到了问题: 先是下载过程中有许多警告,然后就是提示无法跳断点,找不到main方法,每次烧程序都出现: The stack p ...

  7. 使用ajax获取JSON数据的jQuery代码的格式

    具体的也可以参考:http://www.w3cfuns.com/notes/16039/2b004b1bcdf79092f2e66b2bbe9f51df.html

  8. Swift3.0P1 语法指南——基础

    原档:https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programmi ...

  9. lua操作json,mysql,redis等

    ==========================example for lua json======================= local cjson = require("cj ...

  10. ubutu之jdk安装

    1.jdk下载 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html 2.解压jdk- ...