diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-02 19:35:38 +0100 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-05-02 19:35:38 +0100 |
| commit | 6c6480baed8abb849ed2d2ffa29f5e8710b64268 (patch) | |
| tree | 11a9f98fa80ea6e5d972901318d89626f204f70a /challenge-215/ulrich-rieke/cpp/ch-1.cpp | |
| parent | 842c3a85ecdec22547f7d78e3a118ec735bab197 (diff) | |
| download | perlweeklychallenge-club-6c6480baed8abb849ed2d2ffa29f5e8710b64268.tar.gz perlweeklychallenge-club-6c6480baed8abb849ed2d2ffa29f5e8710b64268.tar.bz2 perlweeklychallenge-club-6c6480baed8abb849ed2d2ffa29f5e8710b64268.zip | |
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-215/ulrich-rieke/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-215/ulrich-rieke/cpp/ch-1.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/challenge-215/ulrich-rieke/cpp/ch-1.cpp b/challenge-215/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..5f874934ed --- /dev/null +++ b/challenge-215/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,28 @@ +#include <iostream> +#include <string> +#include <vector> +#include <algorithm> + +std::vector<std::string> split( const std::string & startline , + const std::string & sep ) { + std::vector<std::string> separated ; + std::string::size_type start { 0 } ; + std::string::size_type pos ; + do { + pos = startline.find_first_of( sep , start ) ; + separated.push_back( startline.substr(start , pos - start )) ; + start = pos + 1 ; + } while ( pos != std::string::npos ) ; + return separated ; +} + +int main( ) { + std::cout << "Please enter some words, separated by blanks!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector<std::string> allStrings ( split( line , " " ) ) ; + std::cout << std::count_if( allStrings.begin( ) , allStrings.end( ) , + []( auto s ) { std::string c = s ; std::sort( c.begin( ) , + c.end( ) ) ; return c != s ; } ) << std::endl ; + return 0 ; +} |
