字串處理

2021-06-22 14:27:46 字數 886 閱讀 7529

1、kmp演算法:

參考資料:1.1 

1.2  《大話資料結構》

**實現:/*求模式串t中的next函式修正值並存入陣列nextval*/

/* 通過計算返回子串t的next陣列。 */

void get_next(string t, int *next) 

else 

j= next[j]; /* 若字元不相同,則j值回溯 */}}

/* 返回子串t在主串s中第pos個字元之後的位置。若不存在,則函式返回值為0。 */

/*  t非空,1≤pos≤strlength(s)。 */

int index_kmp(string s, string t, int pos) 

else /* 指標後退重新開始匹配 */

j = next[j];/* j退回合適的位置,i值不變 */

}if (j > t[0]) 

return i-t[0];

else 

return 0;

}/* 求模式串t的next函式修正值並存入陣列nextval */

void get_nextval(string t, int *nextval) 

else 

j= nextval[j];/* 若字元不相同,則j值回溯 */}}

int index_kmp1(string s, string t, int pos) 

else /* 指標後退重新開始匹配 */

j = next[j];/* j退回合適的位置,i值不變 */

}if (j > t[0]) 

return i-t[0];

else 

return 0;

}2、boyer-moore演算法

參考資料:

字串處理 字串反轉

請原諒博主今天很閒,於是乎博主又開始更新微博了。這次要更新的問題是 編寫乙個函式,反轉乙個單詞的順序。例如 do or do not,there is no try.就要反轉成 try.no is there not,do or do 大家要認真看看這道題,這道題和大家想象的貌似有點不同。首先字串反...

字串處理

uncode與ansi字串轉換 我們使用windows函式multibytetowidechar將多位元組字串轉換成寬字元字串。函式如下 int multibytetowidechar uintcodepage dworddwflags lpcstrlpmultibytestr intcbmulti...

字串處理

byte array new byte 2 array system.text.encoding.default.getbytes 啊 int i1 short array 0 0 int i2 short array 1 0 unicode解碼方式下的漢字碼 array system.text.e...