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;
}
}
查看全文
相关阅读:
POJ 1815 求最小点割(拆点+枚举割边)
POJ 2391 floyd + 拆点构图 + 二分 + 最大流
POJ 1966 去掉最少的点使得图不连通(最小点割)
sgu 194 无源汇的上下界可行流
POJ 2396 有源汇的上下界可行流(好题)
DIV水平垂直居中
The Struts dispatcher cannot be found
Introduction to 3D Game Programming with Direct X 9.0c读书笔记(1)
Chapter 5Looking Through a Filter(如何将纹理坐标变换到屏幕坐标)
Chapter 6Blurring Things Up之Do It Twice
原文地址:https://www.cnblogs.com/Safe3/p/1409011.html
最新文章
PHP quote_runtime 造成的问题
Zend Framework多模块设置
notification通知配合使用LED灯,附带震动
ImageView的Scaletype属性使用
android代码设置全屏
新来有感..
程序员书单合集
linux网络环境下socket套接字编程(UDP文件传输)
linux下socket编程进程间通信
linux网络编程(socket套接字编程UDP传输)
热门文章
ACM_ICPC hdu2111(简单贪心算法)
为了工作
这钱给你,就是杀你!!(转)
caxa 二次开发序
caxa 二次开发的平台!
POJ 2112 Floyd + 二分 + 构图 + 最大流
POJ 2455 二分+边排序构图+最大流
sgu 176 有源汇的上下界最小流(二分汇源的上界)(好题)
POJ 2135 最小费用流入门题
POJ 1698 构图+最大流
Copyright © 2011-2022 走看看