-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
38 lines (35 loc) · 902 Bytes
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
#include <fstream>
#include "../head/ST.h"
using namespace std;
int main() {
int distinct = 0, words = 0;
int minlen = 8;
ST<string, int> st;
fstream file("/home/ace/AceDev/C++/algorithm/ch3/data/tale.txt");
string key;
// compute frequency counts
while (file >> key) {
if (key.length() < minlen)
continue;
words++;
if (st.contains(key))
st.put(key, st.get(key) + 1);
else {
st.put(key, 1);
distinct++;
}
}
string max;
int vmax = 0;
// find a key with the highest frequency count
for (auto s: st) {
if (s.second > vmax) {
max = s.first;
vmax = s.second;
}
}
cout << max << " " << vmax << " times" << endl;
cout << "distinct = " << distinct << endl;
cout << "words = " << words << endl;
}