Skip to content

Instantly share code, notes, and snippets.

@eXpl0it3r
Last active October 10, 2018 20:44
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 eXpl0it3r/95ce8ecf6307f31296d7537aa24f184a to your computer and use it in GitHub Desktop.
Save eXpl0it3r/95ce8ecf6307f31296d7537aa24f184a to your computer and use it in GitHub Desktop.
I before E except after C
#include <iostream>
#include <fstream>
#include <string>
bool IbEeaC(const std::string& word)
{
for(auto position = word.find("ei"); position != std::string::npos; position = word.find("ei", position += 2))
{
if (position == 0 || word[position - 1] != 'c')
{
return false;
}
}
return word.find("cie") == std::string::npos;
}
int main(int argc, char* argv[])
{
if (argc < 2)
{
std::cout << "Please provide a parameter.\n"
<< "\tIbEeaC <word>\n"
<< "\tIbEeaC <filename>\n";
return -1;
}
auto counter = 0u;
const auto argument = std::string{ argv[1] };
auto file = std::ifstream{ argument, std::ios_base::in };
if (file.is_open())
{
for (auto word = std::string{}; std::getline(file, word);)
{
counter += IbEeaC(word);
}
}
else
{
counter += IbEeaC(argument);
}
std::cout << counter << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment