|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 错过会难过 于 2015-8-21 08:51 编辑
首先感谢 小山童鞋, 用来测试的KMP算法和RK算法的代码是从他的帖子里获得的 .
原帖地址: http://bbs.fishc.com/forum.php?m ... ypeid%26typeid%3D30
KMP算法和RK算法代码和测试代码请移步到小山童鞋的帖子.
- int findByLoop(const char* lStr, const char* rStr)
- {
- // lStr 是包含rStr的字符串(如果有的话)
- // rStr 是需要查找的字符串
- unsigned int i = 0, j = 0;
- unsigned int rStrLength = strlen(rStr) - 1;
- while (lStr[i] != 0){
- if (rStrLength == j){
- return i - rStrLength;
- }
- if (lStr[i] == rStr[j]){
- ++j;
- }
- else if (j > 0 && lStr[i] != rStr[j]){
- --i;
- j = 0;
- }
- ++i;
- }
- return -1;
- }
复制代码
|
-
测试结果
|