Last active
October 10, 2018 20:44
-
-
Save eXpl0it3r/95ce8ecf6307f31296d7537aa24f184a to your computer and use it in GitHub Desktop.
I before E except after C
This file contains hidden or 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 <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