Created
September 10, 2019 14:22
-
-
Save piotrbla/a5a847f2287850a470caba2cc61e7b20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <fstream> | |
#include <map> | |
#include <iterator> | |
#include <string> | |
#include <vector> | |
using namespace std; | |
int main() { | |
fstream file{ "ConsoleApplication2.cpp" }; | |
vector<string> text{ istream_iterator<string>{file}, istream_iterator<string>{} }; | |
map<string, int> counters{}; | |
for (auto& num : text) { | |
int flag = 0; | |
string temp = ""; | |
for (int i = 0; i < num.length(); i++) | |
{ | |
if ((num[i] >= 'a' && num[i] <= 'z') || (num[i] >= 'A' && num[i] <= 'Z') || (num[i] >= '0' && num[i] <= '9') || num[i] == '_') | |
{ | |
temp += num[i]; | |
} | |
else | |
{ | |
if ((temp[0] >= 'a' && temp[0] <= 'z') || (temp[0] >= 'A' && temp[0] <= 'Z') || temp[0] == '_') | |
{ | |
counters[temp]++; | |
temp = ""; | |
continue; | |
} | |
} | |
} | |
} | |
for (const auto & counter : counters) | |
{ | |
std::cout << counter.first << " <> " << counter.second << "\n"; | |
} | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment