【POJ 3461】 Oulipo
2024-08-25 09:47:36
【题目链接】
【算法】
KMP
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXW 10010
#define MAXT 1000010 int T,l1,l2;
char s1[MAXW],s2[MAXT];
int next[MAXW]; template <typename T> inline void read(T &x) {
int f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) { if (c == '-') f = -f; }
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
} template <typename T> inline void write(T x) {
if (x < ) { putchar('-'); x = -x; }
if (x > ) write(x/);
putchar(x%+'');
} template <typename T> inline void writeln(T x) {
write(x);
puts("");
} inline void getnext() {
int i,pos;
next[] = ;
for (i = ; i <= l1; i++) {
pos = next[i-];
while (pos > && s1[pos+] != s1[i]) pos = next[pos];
if (s1[pos+] == s1[i]) next[i] = pos + ;
else next[i] = ;
}
} inline void kmp() {
int i,pos=,sum=;
for (i = ; i <= l2; i++) {
while (pos > && s2[i] != s1[pos+]) pos = next[pos];
if (s2[i] == s1[pos+]) pos++;
else pos = ;
if (pos == l1) sum++;
}
writeln(sum);
} int main() { read(T);
while (T--) {
scanf("%s%s",s1+,s2+);
l1 = strlen(s1+); l2 = strlen(s2+);
getnext();
kmp();
} return ; }
最新文章
- 理解Docker(3):Docker 使用 Linux namespace 隔离容器的运行环境
- [原创]直播服务器简单实现 http_flv和hls 内网直播桌面
- 子句jion
- C#:WebBrowser控件设置代理IP访问网站【附源码】
- 2014 Super Training #7 C Diablo III --背包问题(DP)
- 浅析ado.net获取数据库元数据信息 DeriveParameters
- bzoj3721 [PA2014 Final] Bazarek
- linux下执行strlwr函数出错:ld returned 1 exit status
- H2最完整的资料下载地址:
- 利用angular控制元素的显示和隐藏
- JavaScript: 使用 atan2 来绘制 箭头 和 曲线
- 安装selenium
- Django---手动编写视图
- 配置Nim的默认编译参数 release build并运行
- 深入理解java虚拟机(二)-----垃圾回收
- C# Winfrom MDI(多文档界面)
- array扩展运算符
- sqlserver创建计算列 转
- ASP.NET 实现多页面合并一页显示
- 基于Kafka+Spark Streaming+HBase实时点击流案例
热门文章
- Codeforces 123 E Maze
- BZOJ3674 可持久化并査集
- error MIDL2311 解决方法
- DELPHI方法注释的标准写法
- People seldom do what they believe in. They do what is convenient, then repent.
- 利用反射技术实现POJO的数据库操作
- 【Java编程】建立一个简单的JDBC连接-Drivers, Connection, Statement and PreparedStatement
- 重新认识一遍JavaScript
- python—networkx:依据图的权重绘图
- poj 2154 Color 欧拉函数优化的ploya计数