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;
}
}
查看全文
相关阅读:
nyoj 202 红黑树
nyoj 237 游戏高手的烦恼
nyoj 203 三国志
nyoj 118 修路方案
nyoj 714 Card Trick
nyoj 710 外星人的供给站
nyoj 712探 寻 宝 藏
nyoj 709 异 形 卵
nyoj 711 最舒适的路线
HTML5表格简单应用案例之[招聘需求表]
原文地址:https://www.cnblogs.com/Safe3/p/1409011.html
最新文章
Case when
业务
jQuery中设置form表单中action值的方法
SQL_SERVER日期函数详细用法
SQL Server中的sysobjects
浅析StackTrace【转】
SQLServer中临时表与表变量的区别分析【转】
C#中的反射原理及应用(转)
查看SQL执行计划
Vue(小案例_vue+axios仿手机app)_首页(底部导航栏+轮播图+九宫格)
热门文章
Vue(项目踩坑)_解决vue中axios请求跨域的问题
Vue(基础八)_导航守卫(组件内的守卫)
Vue(基础七)_webpack(webpack异步加载原理)
Vue(基础七)_webpack(CommonsChunkPlug的使用)
Vue(基础七)_webpack打包工具(续)
Vue(基础七)_webpack使用工具(下)
Vue(基础七)_webpack打包工具用法(上)
Vue(基础六)_嵌套路由(续)
Vue(基础六)_vue-router
nyoj 738 Calendar Game
Copyright © 2011-2022 走看看