aboutsummaryrefslogtreecommitdiff
path: root/challenge-216/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-11 23:29:02 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2023-05-11 23:29:02 +0100
commit6129c5d5a28972223b3b9df7d90179b9cd35493d (patch)
treede26b1e506e87a801c2209e93f6804074427a382 /challenge-216/ulrich-rieke/cpp/ch-1.cpp
parentd56749df940d5687c02afd8743c56172fa997a13 (diff)
downloadperlweeklychallenge-club-6129c5d5a28972223b3b9df7d90179b9cd35493d.tar.gz
perlweeklychallenge-club-6129c5d5a28972223b3b9df7d90179b9cd35493d.tar.bz2
perlweeklychallenge-club-6129c5d5a28972223b3b9df7d90179b9cd35493d.zip
- Added solutions by Ulrich Rieke.
- Added solutions by Roger Bell_West. - Added solutions by David Ferrone. - Added solutions by Peter Campbell Smith. - Added solutions by Thomas Kohler. - Added solutions by Arne Sommer. - Added solutions by Jaldhar H. Vyas.
Diffstat (limited to 'challenge-216/ulrich-rieke/cpp/ch-1.cpp')
-rw-r--r--challenge-216/ulrich-rieke/cpp/ch-1.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/challenge-216/ulrich-rieke/cpp/ch-1.cpp b/challenge-216/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..e51a101c2a
--- /dev/null
+++ b/challenge-216/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,55 @@
+#include <iostream>
+#include <vector>
+#include <string>
+#include <cctype>
+
+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 ;
+}
+
+bool condition( const std::string & regi , const std::string & word ) {
+ for ( std::string::size_type i = 0 ; i < regi.length( ) ; i++ ) {
+ if ( word.find( regi.substr( i , 1 ) ) == std::string::npos ) {
+ return false ;
+ }
+ }
+ return true ;
+}
+
+int main( ) {
+ std::cout << "Please enter some words, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> words ( split( line , " " ) ) ;
+ std::cout << "Enter , separated by blanks, 2 parts of a registration number!\n" ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> regiparts( split( line , " " ) ) ;
+ std::string registration ( regiparts[ 0 ] + regiparts[ 1 ] ) ;
+ std::string relevant_word ;
+ for ( auto c : registration ) {
+ if ( std::isalpha( c ) )
+ relevant_word.push_back( static_cast<char>( tolower( c ) ) ) ;
+ }
+ std::vector<std::string> selected ;
+ for ( auto word : words )
+ if ( condition ( relevant_word , word ) )
+ selected.push_back( word ) ;
+ std::cout << "(" ;
+ for ( auto word : selected ) {
+ std::cout << word ;
+ if ( word != selected.back( ) )
+ std::cout << " , " ;
+ else
+ std::cout << ")\n" ;
+ }
+ return 0 ;
+}