POJ3461 Oulipo(kmp)
来源:互联网 发布:无缝贴图软件 编辑:程序博客网 时间:2024/05/16 19:57
题目链接:点击打开链接
给你两个字符串,问你前一个字符串在后一个字符串中出现了几次。
简单修改hdoj2087代码即可ac,就是交换了一下输入顺序,以及此题kmp()函数中j不归零。
AC代码:
#include "iostream"#include "cstdio"#include "cstring"#include "algorithm"using namespace std;const int MAXN = 1e6 + 6;char s1[MAXN], s2[MAXN];int nxt[MAXN], len1, len2;void get_nxt(){nxt[1] = 0;int j = 0;for(int i = 2; i <= len2; ++i) {while(j > 0 && s2[j + 1] != s2[i])j = nxt[j];if(s2[j + 1] == s2[i]) j++;nxt[i] = j;}}int kmp(){int j = 0, ans = 0;for(int i = 1; i <= len1; ++i) {while(j > 0 && s2[j + 1] != s1[i])j = nxt[j];if(s2[j + 1] == s1[i]) j++;if(j == len2) ans++;}return ans;}int main(int argc, char const *argv[]){int t;scanf("%d", &t);while(t--) {scanf("%s", s2 + 1);scanf("%s", s1 + 1);memset(nxt, 0, sizeof(nxt));len1 = strlen(s1 + 1), len2 = strlen(s2 + 1);get_nxt();printf("%d\n", kmp());}return 0;}
1 0
- 【KMP】 poj3461 Oulipo
- 【KMP】Oulipo POJ3461
- poj3461 Oulipo (kmp)
- [POJ3461] Oulipo[KMP基础]
- poj3461 Oulipo,Kmp
- POJ3461 Oulipo 【KMP】
- POJ3461 Oulipo KMP
- poj3461-Oulipo(KMP)
- poj3461 Oulipo【KMP】
- 【KMP】【POJ3461】Oulipo
- POJ3461 Oulipo(kmp)
- poj3461 Oulipo(KMP)
- 【poj3461】Oulipo(KMP)
- poj3461 Oulipo(KMP)
- POJ3461 Oulipo KMP基础
- poj3461 Oulipo(KMP)
- POJ3461 Oulipo KMP裸题
- 【POJ3461】Oulipo(KMP)
- 自动布局Autoresizing autolayout VFL
- POJ - 2785 4 Values whose Sum is 0(二分搜索)
- POJ2752 Seek the Name, Seek the Fame(kmp)
- JS点名神器
- php获取内容中的所有图片
- POJ3461 Oulipo(kmp)
- Java 基本类型 long 的一些使用陷阱
- IOS HTTP GET POST学习笔记
- 迅雷 API 接口说明文档 -调用迅雷自动下载
- HTTP协议规定的 - URL中的保留字符
- 手势识别器
- Unity的Socket通讯_3_粘包丢包
- scanf不判断是否读到EOF导致 output limit exceed
- *LeetCode-Scramble String