diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-10-04 20:17:51 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2022-10-04 20:17:51 +0100 |
| commit | c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af (patch) | |
| tree | 2975f24483e974256c048b6ccb9d6002733b20e9 /challenge-185/ulrich-rieke/cpp/ch-2.cpp | |
| parent | df70f22400eb0a746fe221429e8a239407e3348e (diff) | |
| download | perlweeklychallenge-club-c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af.tar.gz perlweeklychallenge-club-c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af.tar.bz2 perlweeklychallenge-club-c2c9d22ffcf55b02aa3a5aeda5553f5b556e81af.zip | |
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-185/ulrich-rieke/cpp/ch-2.cpp')
| -rw-r--r-- | challenge-185/ulrich-rieke/cpp/ch-2.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-185/ulrich-rieke/cpp/ch-2.cpp b/challenge-185/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..cc3d7b73ae --- /dev/null +++ b/challenge-185/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,45 @@ +#include <iostream> +#include <string> +#include <cctype> +#include <algorithm> +#include <vector> + +std::string substitute( const std::string & word ) { + std::string output ; + int count = 0 ; + int pos = 0 ; + while ( count < 4 ) { + if (std::isalnum( static_cast<int>(word[ pos ] )) != 0 ) { + output.append( "x") ; + pos++ ; + count++ ; + } + else { + output.append( word.substr( pos, 1 )) ; + pos++ ; + } + } + output.append( word.substr( pos )) ; + return output ; +} + +int main( ) { + std::cout << "Please enter codes with a minimum length of 4!\n" ; + std::cout << "Enter an empty string to end!\n" ; + std::vector<std::string> allInput ; + std::string line ; + std::getline( std::cin , line ) ; + while ( line.length( ) > 0 ) { + allInput.push_back( line ) ; + std::getline( std::cin , line ) ; + } + std::transform( allInput.begin( ) , allInput.end( ) , allInput.begin( ), + substitute ) ; + for ( auto & s : allInput ) { + std::cout << s ; + if ( s != allInput.back( ) ) + std::cout << " , " ; + } + std::cout << std::endl ; + return 0 ; +} |
