From 642b9c4df5cd463cbb354cbcfbefecb97cc97fa5 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Tue, 27 Sep 2022 09:48:40 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-184/ulrich-rieke/cpp/ch-2.cpp | 54 +++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 challenge-184/ulrich-rieke/cpp/ch-2.cpp (limited to 'challenge-184/ulrich-rieke/cpp/ch-2.cpp') diff --git a/challenge-184/ulrich-rieke/cpp/ch-2.cpp b/challenge-184/ulrich-rieke/cpp/ch-2.cpp new file mode 100644 index 0000000000..4f05b42cf2 --- /dev/null +++ b/challenge-184/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include +#include + +int main( ) { + std::cout << "Please enter lines of letters and digits only, separated by blanks!\n" ; + std::cout << "enter to end!\n" ; + std::string line ; + std::getline( std::cin , line ) ; + std::vector allInput ; + while ( !line.empty( ) ) { + allInput.push_back( line ) ; + std::getline( std::cin , line ) ; + } + std::vector> allDigits ; + std::vector> allLetters ; + for ( const auto & s : allInput ) { + std::vector currentDigits ; + std::vector currentLetters ; + for ( char c : s ) { + if ( std::islower( c ) ) { + currentLetters.push_back( c ) ; + } + if ( std::isdigit( c ) ) { + currentDigits.push_back( c ) ; + } + } + if ( currentDigits.size( ) > 0 ) { + allDigits.push_back( currentDigits ) ; + } + if ( currentLetters.size( ) > 0 ) { + allLetters.push_back( currentLetters ) ; + } + } + std::cout << '[' ; + for ( const auto & sequence : allDigits ) { + std::cout << "[ " ; + std::copy( sequence.begin( ) , sequence.end( ) , std::ostream_iterator( + std::cout , " " )) ; + std::cout << "]," ; + } + std::cout << "] and [" ; + for ( const auto & sequence : allLetters ) { + std::cout << "[ " ; + std::copy( sequence.begin( ) , sequence.end( ) , std::ostream_iterator( + std::cout , " " )) ; + std::cout << "]," ; + } + std::cout << ']' << std::endl ; + return 0 ; +} -- cgit