SDUT 2772 数据结构实验之串一:KMP简单应用
数据结构实验之串一:KMP简单应用
Problem Description
Input
Output
Example Input
abc a 123456 45 abc ddd
Example Output
1 4 -1
DQE:
#include <iostream>
#include <cstdio>
using namespace std;
int strlen(char *s)
{
;
while(s[i]!='\0')
{
i++;
}
return i;
}
void cnext(char *s,int *next)
{
int l=strlen(s);
,j=-;
next[i]=j;
)
{
||s[i]==s[j])
{
i++;
j++;
next[i]=j;
}
else
{
j=next[j];
}
}
}
int kmp(char *s1,char *s2,int *next)
{
int l1=strlen(s1),l2=strlen(s2);
,j=;
while(i<l1&&j<l2)
{
||s1[i]==s2[j])
{
i++;
j++;
}
else
{
j=next[j];
}
}
if(j>=l2)
;
;
}
int main()
{
],s2[];
]; //此处用static不完全等同于放到全局变量
while(gets(s1))
{
gets(s2);
cnext(s2,next);
printf("%d\n",kmp(s1,s2,next));
}
;
}
/***************************************************
User name: ***
Result: Accepted
Take time: 68ms
Take Memory: 1012KB
Submit time: 2016-11-02 21:33:59
****************************************************/
SDUT 2772 数据结构实验之串一:KMP简单应用的更多相关文章
- SDUT 3311 数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 有n个小朋友 ...
- SDUT OJ 数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT OJ 数据结构实验之串一:KMP简单应用 && 浅谈对看毛片算法的理解
数据结构实验之串一:KMP简单应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT OJ 数据结构实验之串二:字符串匹配
数据结构实验之串二:字符串匹配 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT-3331_数据结构实验之串三:KMP应用
数据结构实验之串三:KMP应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 有n个小朋友,每个小朋友手里有一些糖块, ...
- SDUT-2772_数据结构实验之串一:KMP简单应用
数据结构实验之串一:KMP简单应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 给定两个字符串string1和str ...
- SDUT 3401 数据结构实验之排序四:寻找大富翁.!
数据结构实验之排序四:寻找大富翁 Time Limit: 150MS Memory Limit: 512KB Submit Statistic Problem Description 2015胡润全球 ...
- SDUT 3346 数据结构实验之二叉树七:叶子问题
数据结构实验之二叉树七:叶子问题 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知一个按 ...
- SDUT 3347 数据结构实验之数组三:快速转置
数据结构实验之数组三:快速转置 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 转置运算是一 ...
随机推荐
- 在VS 2010中使用 VS2013的解决方案
本文转载自:http://blog.csdn.net/u011543589/article/details/25563351 今天要用VS2010打开VS2013,一直觉得VS2010到VS2012只 ...
- 域控制器中的FSMO角色
FSMO是Flexible single master operation的缩写,意思就是灵活单主机操作.营运主机(Operation Masters,又称为Flexible Single Maste ...
- 如何添加WebService调用时的用户认证
场景: 当把发布好的WebService地址或WSDL提供给调用方时,需要对方先进行身份的认证通过后才允许接口的进步访问.而不是公开的谁都可以调用. 解决: 1.在IIS中设置对应网站的目录访问权限. ...
- c++常用的一些库函数、常量和头文件
1.常用数学函数 头文件 #include <math> 或者 #include <math.h> 函数原型 功能 返回值 int abs(int x) 求整数x的绝对值 ...
- 黄聪:怎么清理win7、win8更新垃圾(winsxs目录清理)
windows 系统(特别是Win8系统)在使用了一段时间后,发现C盘的空间降的好厉害,显然,有大量不该存在的文件还继续停留在硬盘里.究其原因,在于系统目录下的WinSxS目录占用了大量的空间!在我们 ...
- mvc 控制器,视图,Razor 语法
mvc 控制器controller:响应用户请求,并修改模型model;输入数据的处理,输出view数据的提供: url入控制器的方法有关联:MVC提供的是方法调用结果: mvc model:是对应用 ...
- (C#) What is the difference between "const" and "static readonly" ?
const int a must be initialized initialization must be at compile time readonly int a can use defaul ...
- Maven本地安装JAR包组件
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/ mvn instal ...
- NSString类的相关用法
一.NSString字符串连接NSString* string; // 结果字符串 NSString* string1, string2; //已存在的字符串 1. string = [NSStrin ...
- UVA 253 Cube painting(暴力打表)
Cube painting Problem Description: We have a machine for painting cubes. It is supplied with three d ...