diff options
| author | Paulo Custodio <pauloscustodio@gmail.com> | 2023-04-07 11:52:10 +0100 |
|---|---|---|
| committer | Paulo Custodio <pauloscustodio@gmail.com> | 2023-04-07 11:52:10 +0100 |
| commit | c27917c2860cb2a203262d9cdeebd264c29456f2 (patch) | |
| tree | 3b024d7c86e48d197d470779ceca31d31a6971a5 /challenge-211/ulrich-rieke/cpp/ch-1.cpp | |
| parent | bd0ea1891b53fb4cff93b57af6481f37dd268509 (diff) | |
| parent | 419cb48e0bd7736f9b625a9f60ce52bc77be8f7a (diff) | |
| download | perlweeklychallenge-club-c27917c2860cb2a203262d9cdeebd264c29456f2.tar.gz perlweeklychallenge-club-c27917c2860cb2a203262d9cdeebd264c29456f2.tar.bz2 perlweeklychallenge-club-c27917c2860cb2a203262d9cdeebd264c29456f2.zip | |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'challenge-211/ulrich-rieke/cpp/ch-1.cpp')
| -rw-r--r-- | challenge-211/ulrich-rieke/cpp/ch-1.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
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 <vector> +#include <string> +#include <algorithm> +#include <iostream> + +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 ; +} + +int main( ) { + std::cout << "Enter some matrices with same number of integers, end to end!\n" ; + std::string line ; + std::vector<std::vector<int>> matrix ; + std::vector<int> numberline ; + std::getline( std::cin , line ) ; + while ( line != "end" ) { + std::vector<std::string> 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<int> diagonals ; + for ( int i = 0 ; i < len ; i++ ) { + std::vector<int> 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 ; +} |
