aboutsummaryrefslogtreecommitdiff
path: root/challenge-184/ulrich-rieke/cpp/ch-2.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2022-09-27 09:48:40 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2022-09-27 09:48:40 +0100
commit642b9c4df5cd463cbb354cbcfbefecb97cc97fa5 (patch)
treef389ae9815c2884a8eb405663d23554f5fd6c30e /challenge-184/ulrich-rieke/cpp/ch-2.cpp
parentd2dbff2eae0647c51ba7795ed75b7978b1896177 (diff)
downloadperlweeklychallenge-club-642b9c4df5cd463cbb354cbcfbefecb97cc97fa5.tar.gz
perlweeklychallenge-club-642b9c4df5cd463cbb354cbcfbefecb97cc97fa5.tar.bz2
perlweeklychallenge-club-642b9c4df5cd463cbb354cbcfbefecb97cc97fa5.zip
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-184/ulrich-rieke/cpp/ch-2.cpp')
-rw-r--r--challenge-184/ulrich-rieke/cpp/ch-2.cpp54
1 files changed, 54 insertions, 0 deletions
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 <iostream>
+#include <string>
+#include <vector>
+#include <cctype>
+#include <iterator>
+#include <algorithm>
+
+int main( ) {
+ std::cout << "Please enter lines of letters and digits only, separated by blanks!\n" ;
+ std::cout << "enter <return> to end!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> allInput ;
+ while ( !line.empty( ) ) {
+ allInput.push_back( line ) ;
+ std::getline( std::cin , line ) ;
+ }
+ std::vector<std::vector<int>> allDigits ;
+ std::vector<std::vector<char>> allLetters ;
+ for ( const auto & s : allInput ) {
+ std::vector<int> currentDigits ;
+ std::vector<char> 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<char>(
+ std::cout , " " )) ;
+ std::cout << "]," ;
+ }
+ std::cout << "] and [" ;
+ for ( const auto & sequence : allLetters ) {
+ std::cout << "[ " ;
+ std::copy( sequence.begin( ) , sequence.end( ) , std::ostream_iterator<char>(
+ std::cout , " " )) ;
+ std::cout << "]," ;
+ }
+ std::cout << ']' << std::endl ;
+ return 0 ;
+}