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;
}
}
查看全文
相关阅读:
Sharepoint 2013默认dll部署位置
Sharepoint 2010 Form认证自定义登录页面,总是自动登录问题
cocos打包后页面在ios浏览器、安卓钉钉等部分app中横竖屏问题
cocos构建出来的 Web Mobile 项目在微信开发者工具里面无法点击
git 合并某个提交commit到指定的分支上
cc.sys.localStorage存储和读取用户数据
cocos creater关于blend,关于预乘premultiply alpha,关于图片白边灰边的问题
cocos遮罩层点击穿透问题解决
postman中 form-data、x-www-form-urlencoded、raw、binary操作
‘webpack-dev-server' 不是内部或外部命令,也不是可运行的程序
原文地址:https://www.cnblogs.com/Safe3/p/1409011.html
最新文章
依赖管理(require.context)
性能和代码之间的权重
对于组件的看法
java中的反射(一)
java中的各种锁
【面试题】在浏览器中输入URL后,执行的全部过程。会用到哪些协议?(一次完整的HTTP请求过程)
【面试】java什么时候要用static
免费音乐、视频、图片、字体素材网站
Spring学习笔记(二)
【面试题】创建线程有几种方式?
热门文章
几种必知的软件架构模式
Dr.COM获取用户属性超时!请检查防火墙配置允许UDP 61440端口。怎么解决
Sharepoint中设置域组权限域组中人员还是没有权限
IE10下__doPostBack is undefined bug
JS获取时间段内的工作时长
MVC显示子视图并获取后台数据
2016年开始
Entity Framework主键和非自增长
AD服务器不愿意处理该请求
Code First添加一个现有数据库中的表
Copyright © 2011-2022 走看看