diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-07-22 13:50:28 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-07-22 13:50:28 +0100 |
| commit | 274bf4a39a2a89b95ebbc89cea4d775f2c8eaead (patch) | |
| tree | 1e8169c57fcd742a6f6d337300182ec6772b9a2a /challenge-279/ulrich-rieke/cpp | |
| parent | 68787dcb78ada3349ae5f986f2cc39f33a665029 (diff) | |
| download | perlweeklychallenge-club-274bf4a39a2a89b95ebbc89cea4d775f2c8eaead.tar.gz perlweeklychallenge-club-274bf4a39a2a89b95ebbc89cea4d775f2c8eaead.tar.bz2 perlweeklychallenge-club-274bf4a39a2a89b95ebbc89cea4d775f2c8eaead.zip | |
- Added solutions by Ulrich Rieke.
Diffstat (limited to 'challenge-279/ulrich-rieke/cpp')
| -rwxr-xr-x | challenge-279/ulrich-rieke/cpp/ch-1.cpp | 38 | ||||
| -rwxr-xr-x | challenge-279/ulrich-rieke/cpp/ch-2.cpp | 14 |
2 files changed, 52 insertions, 0 deletions
diff --git a/challenge-279/ulrich-rieke/cpp/ch-1.cpp b/challenge-279/ulrich-rieke/cpp/ch-1.cpp new file mode 100755 index 0000000000..8d6d6444c8 --- /dev/null +++ b/challenge-279/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,38 @@ +#include <iostream>
+#include <string>
+#include <algorithm>
+#include <utility>
+#include <sstream>
+#include <vector>
+
+std::vector<std::string> tokenize( const std::string & text , char delimiter ) {
+ std::istringstream allTokens { text } ;
+ std::vector<std::string> tokens ;
+ std::string tok ;
+ while ( std::getline( allTokens , tok , delimiter ) ) {
+ tokens.push_back( tok ) ;
+ }
+ return tokens ;
+}
+
+int main( ) {
+ std::cout << "Enter some letters, separated by blanks!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> letterstrings { tokenize( line , ' ' ) } ;
+ std::cout << "Enter some weights, separated by blanks!\n" ;
+ std::getline( std::cin , line ) ;
+ std::vector<std::string> weightstrings { tokenize( line , ' ' ) } ;
+ std::vector<std::pair<char , int>> allPairs ;
+ for ( int i = 0 ; i < letterstrings.size( ) ; i++ ) {
+ allPairs.push_back( std::make_pair( letterstrings[i].front( ) , std::stoi(
+ weightstrings[i].substr( 0 , 1 ) ) ) ) ;
+ }
+ std::sort( allPairs.begin( ) , allPairs.end( ) , []( const auto & p1 , const auto & p2) {
+ return p1.second < p2.second ; } ) ;
+ for ( auto p : allPairs )
+ std::cout << p.first ;
+ std::cout << '\n' ;
+ return 0 ;
+}
+
diff --git a/challenge-279/ulrich-rieke/cpp/ch-2.cpp b/challenge-279/ulrich-rieke/cpp/ch-2.cpp new file mode 100755 index 0000000000..84455bf78a --- /dev/null +++ b/challenge-279/ulrich-rieke/cpp/ch-2.cpp @@ -0,0 +1,14 @@ +#include <string>
+#include <algorithm>
+#include <iostream>
+
+int main( ) {
+ std::cout << "Enter a string!\n" ;
+ std::string line ;
+ std::getline( std::cin , line ) ;
+ std::string vowels {"aeiouAEIOU"} ;
+ std::cout << std::boolalpha << (std::count_if( line.begin( ) , line.end( ),
+ [vowels]( char c ) { return vowels.find( c ) != std::string::npos ;
+ } ) % 2 == 0 ) << '\n' ;
+ return 0 ;
+}
|
