-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathfindFreqWordinBook.cpp
More file actions
48 lines (43 loc) · 1.14 KB
/
Copy pathfindFreqWordinBook.cpp
File metadata and controls
48 lines (43 loc) · 1.14 KB
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
39
40
41
42
43
44
45
46
47
48
#include <unordered_map>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;
unordered_map <string, int> setupDictionary(vector<string> book)
{
unordered_map<string, int> table;
for (int i =0;i< book.size(); i++)
{
string word = book[i];
if(word != "")
{
if (table.find(word)==table.end())
{
std::pair<std::string,int> myshopping (word,1);
table.insert(myshopping);
}else
{
int num = table[word];
std::pair<std::string,int> myshopping (word,num+1);
table.insert(myshopping );
}
}
}
return table;
}
int main()
{
vector<string> book(4);
book.push_back( "hello");
book.push_back("world");
book.push_back ("hello");
book.push_back ("world2");
unordered_map < string, int> dict= setupDictionary(book);
printf("%d", dict.size());
for (unordered_map<string,int>::iterator it = dict.begin(); it != dict.end(); ++it)
{
cout<< it->first <<it->second << endl;
}
}