zoukankan
html css js c++ java
字符串搜索的Sunday算法
public
class
SUNDAY
{
public
SUNDAY()
{
//
//
TODO: 在此处添加构造函数逻辑
//
}
public
int
QfindChr(
string
str,
string
Sfind)
{
int
str_length
=
0
;
int
fin_length
=
0
;
int
find_count
=
0
;
int
start
=
0
;
int
moveNum
=
0
;
if
(str.Length
<
Sfind.Length)
{
return
find_count;
}
str_length
=
str.Length;
fin_length
=
Sfind.Length;
while
(start
+
fin_length
<=
str_length)
{
moveNum
++
;
bool
isfind
=
false
;
//
是否在这次移动中找到
string
s_temp
=
str.Substring(start, fin_length);
if
(s_temp
==
Sfind)
{ find_count
++
; start
=
start
+
fin_length; isfind
=
true
; }
if
(isfind
==
false
)
//
如果没找到计算下次移动位置
{
int
forwardPos
=
QfindPos(str, Sfind, start, fin_length);
start
=
forwardPos;
}
}
return
find_count;
}
//
找字符在字符串(不算最后一个字符)的位置(倒数)
//
没找到返回fin_length,找到返回位置
/**/
///
<summary>
///
找字符在字符串(不算最后一个字符)的位置(倒数);没找到返回str.length,找到返回位置
///
</summary>
///
<param name="str"></param>
///
<param name="find"></param>
///
<param name="pos"></param>
///
<param name="fin_length"></param>
///
<returns></returns>
public
int
QfindPos(
string
str,
string
find,
int
pos,
int
fin_length)
{
int
returnPos
=
str.Length;
char
[] Schr
=
str.ToCharArray();
char
[] Sfin
=
find.ToCharArray();
if
((pos
+
fin_length)
<
str.Length)
{
char
chrFind
=
Schr[pos
+
fin_length];
//
要找的字符
if
(fin_length
>=
1
)
{
if
(find.LastIndexOf(chrFind)
>
-
1
)
{
returnPos
=
pos
+
fin_length
-
find.LastIndexOf(chrFind);
}
else
{
returnPos
=
pos
+
fin_length
+
1
;
}
}
}
return
returnPos;
}
}
查看全文
相关阅读:
关于Monitor和lock的锁操作 笔记
模型/数据验证(System.ComponentModel.DataAnnotations)笔记
NSIS 打包操作
关于IE和非IE浏览器的一些差异笔记
Wpf 字典触发器
关于MongoDB在C#的使用
Apache JMeter
关于在移动端方面的css应用
关于csc.exe
增量运算符+=和*=的原理与不可变序列增量运算效率低的原因
原文地址:https://www.cnblogs.com/Safe3/p/1409011.html
最新文章
主题模型 LDA 入门
主题模型--机器学习
TensorFlow入门之MNIST最佳实践-深度学习
tensorflow模型持久化保存和加载--深度学习-神经网络
RNN概述-深度学习 -神经网络
实现Bidirectional LSTM Classifier----深度学习RNN
Tensorflow中使用tfrecord方式读取数据-深度学习-周振洋
python数据持久存储:pickle模块的基本使用
scipy 图像处理-深度学习
Java实现先把多个文件压缩为zip文件后下载zip文件
热门文章
centos7(脚本)安装配置mysql
FastDFS文件操作-java
CentOS的java环境配置记录
CentOS7安装配置redis记录
CentOS安装配置记录
FastDFS安装配置(CentOS7)
搭建eclipse版的ssm+maven+tk.mybatis+redis及mybatis+spring多数据源配置集成的demo
java使用idea搭建ssm+maven框架项目,单model,精简配置
idea创建空mavenweb项目,从创建项目到创建model,再到tomcat发布测试
2020年又瞎几把总结
Copyright © 2011-2022 走看看