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. Subversion命令汇总

    转自:http://www.cnblogs.com/cnblogsfans/archive/2010/03/21/1690838.html svn 命令共同的选项 --targets list 读取l ...

  2. Entity Framework浅析

    1.Entity Framework简介 http://www.cnblogs.com/aehyok/p/3315991.html 2.Entity Framework DBFirst尝试http:/ ...

  3. 在PHP中遍历数据库表中的数据

    数据库中的数据: //1.分别将每一行的每一列遍历出来 //mysql_fetch_row()函数在每一次遍历后会将指针向后自动移动一个单位 while($row=mysql_fetch_row($r ...

  4. 跨Controllers传数据

    今天遇到两个问题,第一个是跨controller传值,后一个是比较简单的linq数据库查询问题.先描述以下问题我有一个入库单和一个入库明细,入库的逻辑是先填写入库单在填入库明细.两者要么同时完成,要么 ...

  5. c#中两种不同的存储过程调用与比较

    存储过程简介 简单的说,存储过程是由一些SQL语句和控制语句组成的被封装起来的过程,它驻留在数据库中,可以被客户应用程序调用,也可以从另一个过程或触发器调用.它的参数可以被传递和返回.与应用程序中的函 ...

  6. php 正则表达式的使用

    要点:php正则表达式要用双引号,且要用“/ /”斜线做开始结束. 1.preg_match . preg_match_all 两者的区别:第一次匹配成功后就会停止匹配,如果要实现全部结果的匹配,即搜 ...

  7. CSS选择器的特殊性和LOVE HA

    在CSS中当几个相同的选择器对同一个元素有不同的规则时,该怎么应用这些规则呢? 答案就是:CSS特殊性(CSS specificity) 选择器特殊性有选择器本身组成,特殊性由4个数值表述:0, 0, ...

  8. win7平台下React-Native Android:Unable to upload some APKs

    一.问题描述 根据网络上的Win7平台下React-native配置教程配置好开发环境的过程中,在艰难进行到react-native run-android这一步时,发现一直出现错误,截图如下: 错误 ...

  9. Activity的四个启动模式

    /** * Activity有四种启动模式(android:launchMode) * 分别是: * 1. standard(默认),可以不停的在栈中创建新的Activity * 2. singleT ...

  10. 网络之AFNetsorking

    AFNetsorking作为功能全面的网络第三方,既通俗好用又与时俱进-及时的更新使用了NSURLSession,不得不爱. AFNetsorking使用: 1,AFNetsorking GET请求 ...