From a660745f4efb1a8be426529a1f90d3a5a2010a83 Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Wed, 20 Oct 2021 08:23:28 +0100 Subject: - Added solutions by Ulrich Rieke. --- challenge-135/ulrich-rieke/cpp/ch-1.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 challenge-135/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-135/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-135/ulrich-rieke/cpp/ch-1.cpp b/challenge-135/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..098d1b7fee --- /dev/null +++ b/challenge-135/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,28 @@ +#include +#include +#include + +int main( int argc, char * argv[] ) { + std::string input { argv[ 1 ] } ; + std::string checkRegex( "(^[+-]*\\d+$)" ) ; + std::regex checkReg( checkRegex ) ; + while ( ! std::regex_match( input , checkReg ) ) { + std::cout << "Input should consist of possible signs and digits only!\n" ; + std::getline( std::cin , input ) ; + } + int len = input.length( ) ; + if ( ( len == 4 ) ) { + std::string start { input.substr( 0 , 1 ) } ; + if ( (start == "+") || ( start == "-" ) ) + std::cout << input.substr( 1 ) << std::endl ; + } + else { + if ( len % 2 == 0 ) + std::cout << "even number of digits" << std::endl ; + if ( ( len < 3 ) && ( len % 2 != 0 )) + std::cout << "too short" << std::endl ; + if ( ( len % 2 != 0 ) && ( len > 3 ) ) + std::cout << input.substr( ( len - 3 ) / 2 , 3 ) << std::endl ; + } + return 0 ; +} -- cgit