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;
}
}
查看全文
相关阅读:
bzoj 4883 [Lydsy1705月赛]棋盘上的守卫——并查集(思路!)
洛谷 1979 华容道——最短路+dp
51nod 1443 路径和树——最短路生成树
hdu 2222 Keywords Search——AC自动机
bzoj 2067 [Poi2004]SZN——二分+贪心
洛谷 1084 疫情控制——二分答案+贪心(贪心思路!)
CF 1042A Benches——二分答案(水题)
洛谷 1314 聪明的质监员——二分答案
洛谷P3690 LCT模板
bzoj1875 [SDOI2009]HH去散步——矩阵快速幂
原文地址:https://www.cnblogs.com/Safe3/p/1409011.html
最新文章
OC语言(四)
OC语言(三)
OC语言(二)
OC语言(一)
PLSQL显示乱码-无法进行中文条件查询解决
map容器的使用
排序算法(二)Sort with Swap(0,*)
C# 连接 Oracle 的几种方式
致江苏卫视《最强大脑第二季》节目组的一封信
排序算法
热门文章
poj 3070
BZOJ 3209: 花神的数论题
BZOJ 1854: [Scoi2010]游戏
BZOJ 2134: 单选错位
loj #6281. 数列分块入门 5
BZOJ 1874: [BeiJing2009 WinterCamp]取石子游戏
LUOGU P2822 组合数问题
组合数递推(模板)
BZOJ 1008: [HNOI2008]越狱
洛谷 P1155 双栈排序
Copyright © 2011-2022 走看看