From c2b6029560590d89d87180533fc1187b1d6b476e Mon Sep 17 00:00:00 2001 From: Mohammad S Anwar Date: Fri, 7 Apr 2023 02:46:40 +0100 Subject: - Added solutions by Luca Ferrari. - Added solutions by Mark Anderson. - Added solutions by Paulo Custodio. - Added solutions by David Ferrone. - Added solutions by W. Luis Mochan. - Added solutions by Robbie Hatley. - Added solutions by Jorg Sommrey. - Added solutions by Roger Bell_West. - Added solutions by Leo Manfredi. - Added solutions by Arne Sommer. - Added solutions by James Smith. - Added solutions by Peter Meszaros. - Added solutions by Ulrich Rieke. - Added solutions by Robert DiCicco. --- challenge-211/ulrich-rieke/cpp/ch-1.cpp | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 challenge-211/ulrich-rieke/cpp/ch-1.cpp (limited to 'challenge-211/ulrich-rieke/cpp/ch-1.cpp') diff --git a/challenge-211/ulrich-rieke/cpp/ch-1.cpp b/challenge-211/ulrich-rieke/cpp/ch-1.cpp new file mode 100644 index 0000000000..9065b6c7f0 --- /dev/null +++ b/challenge-211/ulrich-rieke/cpp/ch-1.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +std::vector split( const std::string & startline , + const std::string & sep ) { + std::vector 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 ; +} + +int main( ) { + std::cout << "Enter some matrices with same number of integers, end to end!\n" ; + std::string line ; + std::vector> matrix ; + std::vector numberline ; + std::getline( std::cin , line ) ; + while ( line != "end" ) { + std::vector numberstrings ( split( line , " " ) ) ; + for ( auto s : numberstrings ) + numberline.push_back( std::stoi( s ) ) ; + matrix.push_back( numberline ) ; + numberline.clear( ) ; + std::cout << "Enter some numbers, end to end!\n" ; + std::getline( std::cin , line ) ; + } + int len = matrix.size( ) ; + std::vector diagonals ; + for ( int i = 0 ; i < len ; i++ ) { + std::vector subline ( *(matrix.begin( ) + i ) ) ; + diagonals.push_back( subline[ i ] ) ; + } + int comparison = *(diagonals.begin( ) ) ; + if ( std::all_of( diagonals.begin( ) , diagonals.end( ) , [ comparison ] + ( int n ) { return n == comparison ; } ) ) + std::cout << "true" ; + else + std::cout << "false" ; + std::cout << std::endl ; + return 0 ; +} -- cgit