diff options
Diffstat (limited to 'challenge-275/atschneid/cpp')
| -rw-r--r-- | challenge-275/atschneid/cpp/ch-1.cpp | 42 | ||||
| -rw-r--r-- | challenge-275/atschneid/cpp/ch-2.cpp | 32 | ||||
| -rw-r--r-- | challenge-275/atschneid/cpp/makefile | 9 |
3 files changed, 83 insertions, 0 deletions
diff --git a/challenge-275/atschneid/cpp/ch-1.cpp b/challenge-275/atschneid/cpp/ch-1.cpp new file mode 100644 index 0000000000..96a1bfb60a --- /dev/null +++ b/challenge-275/atschneid/cpp/ch-1.cpp @@ -0,0 +1,42 @@ +#include <iostream> +#include <regex> +#include <string> + + +using namespace std; + +int find_unbroken_words( const string& line, const string& letters ) { + string letter_expression = "\\S*[" + letters + "]\\S*"; + + regex allwords_re ("\\S+"); + regex badwords_re (letter_expression, regex::icase ); + + auto all_match = sregex_iterator(line.begin(), line.end(), allwords_re); + auto bad_match = sregex_iterator(line.begin(), line.end(), badwords_re); + auto base = sregex_iterator(); + + return std::distance(all_match, base) - std::distance(bad_match, base); +} + +struct inputline { + string s; + const char* cs; +}; + +int main() { + inputline inputs[] = { + { "Perl Weekly Challenge", "la" }, + { "Perl and Raku", "a" }, + { "Well done Team PWC", "lo" }, + { "The joys of polyglottism", "T" }, + { "The joys o*f polyglottism", "*Tp"} + }; + + for (int i=0; i < 5; i++) { + auto input = inputs[i]; + auto line = input.s; + auto broken_chars = input.cs; + cout << line << ", " << broken_chars << " :: " << find_unbroken_words(line, broken_chars) << "\n"; + } +} + diff --git a/challenge-275/atschneid/cpp/ch-2.cpp b/challenge-275/atschneid/cpp/ch-2.cpp new file mode 100644 index 0000000000..10ded6914d --- /dev/null +++ b/challenge-275/atschneid/cpp/ch-2.cpp @@ -0,0 +1,32 @@ +#include <iostream> + +class fillable_string: public std::string { +public: + void fill_digits(); +}; + +void fillable_string::fill_digits() { + auto s = this->data(); + char fill_char = ' '; + for (int i=0; i < this->size(); i++) { + if (std::isdigit(s[i])) { + s[i] += fill_char - '0'; // to shift the char val + } else { + fill_char = s[i]; + } + } +} + +int main() { + fillable_string inputs[]{ + {"a1c1e1"}, + {"a1b2c3d4"}, + {"b2b"}, + {"a16z"} + }; + for (int i=0; i < 4; i++) { + std::cout << inputs[i] << " => "; + inputs[i].fill_digits(); + std::cout << inputs[i] << '\n'; + } +} diff --git a/challenge-275/atschneid/cpp/makefile b/challenge-275/atschneid/cpp/makefile new file mode 100644 index 0000000000..9c91d50c01 --- /dev/null +++ b/challenge-275/atschneid/cpp/makefile @@ -0,0 +1,9 @@ +CPPFLAGS := -g -std=c++17 -Wall -O3 + +all: ch-1 ch-2 + +ch-1: ch-1.cpp + c++ ch-1.cpp -o ch-1 $(CPPFLAGS) + +ch-2: ch-2.cpp + c++ ch-2.cpp -o ch-2 $(CPPFLAGS) |
