雜湊查詢字串

2021-09-05 21:40:24 字數 850 閱讀 4088

雜湊查詢的優越性:

當查詢的字串長度小於機器字長時,可以把字串當做 long 進行比較。由於移位操作相當快(乙個時鐘週期),所以執行操作花費的時間比較少。

這種查詢辦法通用性不好。( big-endian or little-endian 問題)。但不可否認,它的查詢速度確實快。

//"csdn" 的查詢演算法

//思路是:把 "csdn" 按整數比較。每比較一次,對目標串進行移位操作。

void

dwordsearch(

const

char

pstr, 

const

char

*str )

//判斷開頭相等不

//if

( hash 

==ptarget[index] )

//判斷結尾相等不

// 以後再加吧。

for( index =0

; index 

<

len /4

-1; index++)

}if(  index2 

<=32)

}cout 

<<

"找到的次數:

"<<

poscollect.size()  

<<

endl;

for(  vector

<

size_t

>

::const_iterator iter 

=poscollect.begin(); iter

!=poscollect.end(); iter++)

system( 

"pause");

}

字串查詢(字串雜湊)

這是一道模板題。給定乙個字串 a 和乙個字串 b 求 b在 a 中的出現次數。a和 b中的字元均為英語大寫字母或小寫字母。a中不同位置出現的 b可重疊。輸入格式 輸入共兩行,分別是字串 a和字串 b。輸出格式 輸出乙個整數,表示 b在 a中的出現次數。樣例輸入 zyzyzyz zyz樣例輸出 資料範...

查詢字串

在乙個主串中查詢相應的子串,如 abcdwoshidef 中查詢 woshi 方法 該實現的方法是最簡單的模式匹配方法,時間複雜度較高 include iostream using namespace std int searchstring const char str1,const char s...

查詢字串

qstring startwith 判斷乙個字串是否以某個字串開頭,引數 字串,大小寫敏感 qstring str welcome to you str.startswith welcome qt casesensitive 返回true str.startswith you qt casesens...