aboutsummaryrefslogtreecommitdiff
path: root/challenge-282/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-282/ulrich-rieke/cpp/ch-1.cpp')
-rwxr-xr-xchallenge-282/ulrich-rieke/cpp/ch-1.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-282/ulrich-rieke/cpp/ch-1.cpp b/challenge-282/ulrich-rieke/cpp/ch-1.cpp
new file mode 100755
index 0000000000..aceb6a89fa
--- /dev/null
+++ b/challenge-282/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,25 @@
+#include <iostream>
+#include <vector>
+#include <algorithm>
+#include <string>
+
+int main( ) {
+ std::cout << "Enter a long string consisting of digits only!\n" ;
+ std::string number ;
+ std::cin >> number ;
+ std::vector<std::string> triplets , selected ;
+ int pos = 0 ;
+ while ( pos < number.length( ) - 2 ) {
+ triplets.push_back( number.substr( pos , 3 ) ) ;
+ pos++ ;
+ }
+ std::copy_if( triplets.begin( ) , triplets.end( ) ,
+ std::back_inserter( selected ) , []( const auto & s ) {
+ return s.at( 0 ) == s.at( 1 ) && s.at( 1 ) == s.at( 2 ) ; } ) ;
+ if ( selected.size( ) == 0 )
+ std::cout << -1 << '\n' ;
+ else
+ std::cout << selected[0].substr( 0 , 1 ) << '\n' ;
+ return 0 ;
+}
+