-
Notifications
You must be signed in to change notification settings - Fork 0
/
11_4.cpp
29 lines (26 loc) · 889 Bytes
/
11_4.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
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cctype>
using namespace std;
int main()
{
map<string, size_t> word_count;
set<string> exclude = {"The", "But", "And", "Or", "An", "A",
"the", "but", "and", "or", "an", "a"};
string word;
while(cin >> word){
for(auto &c: word)
c = tolower(c);
//https://en.wikipedia.org/wiki/Erase%E2%80%93remove_idiom erase_remove_idiom
// ispunc should be used with global scope
word.erase(remove_if(word.begin(), word.end(),::ispunct), word.end());
if(exclude.find(word) == exclude.end())
++word_count[word];
}
for(const auto &w : word_count)
cout << w.first << " occurs " << w.second << ((w.second > 1) ? " times" : " time") << endl;
return 0;
}