Skip to content

Instantly share code, notes, and snippets.

@piotrbla
Created September 10, 2019 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save piotrbla/a5a847f2287850a470caba2cc61e7b20 to your computer and use it in GitHub Desktop.
Save piotrbla/a5a847f2287850a470caba2cc61e7b20 to your computer and use it in GitHub Desktop.
#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