#include #include #include #include #include #include #include using namespace std;
typedef struct wordwords;
class node
// 析構函式
~node() {}
// 返回這個節點的內容
char content()
// 設定這個節點的內容
void setcontent(char c)
// 這個節點是否是這個單詞的結束標誌
bool wordmarker()
long wordcount()
// 設定當前的節點為單詞結束標誌
void setwordmarker()
// 給定字元c, 找到這個字元對應當前節點的的孩子節點
node* findchild(char c);
// 放回當前節點的所有孩子節點
vectorchildren()
private:
char mcontent; // 節點的字元
long count; //
bool mmarker; // 該節點是否為單詞的結束位置
vectormchildren; // 該節點的孩子, 是vector of nodes(為這個節點的孩子)};
// 字典樹的類
class trie ;
private:
// 字典樹的根節點
node* root;
static long max_num;};
node* node::findchild(char c)
}// 在當前節點的孩子孩子中沒找到, 返回null
return null;}
long trie:: max_num=0;
trie::trie()
trie::~trie()
void trie::addword(string s)
for ( int i = 0; i < s.length(); i++ )
else
// 最後乙個字元設定這裡的單詞結束標誌
if ( i == s.length() - 1 )
current->setwordmarker();
} }}
long trie::searchword(string s)
if ( current->wordmarker() )
return current->wordcount();
else
return 0;
}return 0;
}static long deal_data(trie *data_trie)
else
outfile.put(ch);
}infile.close();
outfile.close();
ifstream infile1("dealt_data.txt",ios::in);
if(!infile1)
return false ;
}int main()
} if(e_flag)
e_flag=true;
if(i==(num_word-1))
break;
}infile2.close();
//對結構體排序
sort(n_word.begin(),n_word.end(),cmp);
for(i=0;i<10;i++)
delete trie;
return 0;
}``
c 找出序列中出現得最頻繁的值
題目要求 編寫乙個函式模板,接受表示未知型別迭代器的一對值,找出在序列中出現的最頻繁的值。自己寫的 沒有考慮存在出現次數最多且相同的情況,也就是預設輸出第一次最多的數值。include include include using namespace std 找到容器中出現次數最多的值 templat...
查詢乙個陣列中出現次數最多的值(長度為1000)
今天有一道面試題就是這個問題,然後我自己的解決方法是這樣的 var findmost function arr if j arr.length console.log arrl,arrn 列印各個數出現的次數 接下來判斷arrl陣列中最大的值了 maxl arrl 0 for const i of ...
查詢最消耗記憶體的前10個SQL語句
selecttop10 st.textassql full 父級完整語句 substring st.text,qs.statement start offset 2 1,casestatement end offset when 1thendatalength st.text elseqs.stat...