aboutsummaryrefslogtreecommitdiff
path: root/challenge-125/ulrich-rieke/cpp/ch-1.cpp
diff options
context:
space:
mode:
authorScimon <simon.proctor@gmail.com>2021-08-16 09:09:50 +0100
committerScimon <simon.proctor@gmail.com>2021-08-16 09:09:50 +0100
commita40d5274a80b7dc86d043433b77928857d904698 (patch)
tree839fa66142ee3a743bedfe86cc486a5b6573accc /challenge-125/ulrich-rieke/cpp/ch-1.cpp
parentc976e26a845911cf0226844acfc1e4c0e497c8c1 (diff)
parent2d08dfcd1f2742e1621be6950a42614b4dbea797 (diff)
downloadperlweeklychallenge-club-a40d5274a80b7dc86d043433b77928857d904698.tar.gz
perlweeklychallenge-club-a40d5274a80b7dc86d043433b77928857d904698.tar.bz2
perlweeklychallenge-club-a40d5274a80b7dc86d043433b77928857d904698.zip
Merge branch 'master' of github.com:Scimon/perlweeklychallenge-club
Diffstat (limited to 'challenge-125/ulrich-rieke/cpp/ch-1.cpp')
-rw-r--r--challenge-125/ulrich-rieke/cpp/ch-1.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/challenge-125/ulrich-rieke/cpp/ch-1.cpp b/challenge-125/ulrich-rieke/cpp/ch-1.cpp
new file mode 100644
index 0000000000..e0d7336656
--- /dev/null
+++ b/challenge-125/ulrich-rieke/cpp/ch-1.cpp
@@ -0,0 +1,43 @@
+#include <iostream>
+#include <cstdlib>
+#include <algorithm>
+#include <set>
+#include <vector>
+
+int main( int argc , char * argv[] ) {
+ int n = std::atoi( argv[ 1 ] ) ;
+ if ( n > 20 ) {
+ std::cerr << "Number entered should be an integer up to 20!" ;
+ exit( EXIT_FAILURE ) ;
+ return 1 ;
+ }
+ else {
+ std::set<std::vector<int> > triples ;
+ for ( int i = 1 ; i < 101 ; i++ ) {
+ for ( int j = 1 ; j < 101 ; j++ ) {
+ for ( int k = 1 ; k < 101 ; k++ ) {
+ if ( n == i || n == j || n == k ) {
+ if ( i * i + j * j == k * k ) {
+ std::vector<int> triple { i , j , k } ;
+ std::sort( triple.begin( ) , triple.end( ) ) ;
+ triples.insert( triple ) ;
+ }
+ }
+ }
+ }
+ }
+ if ( ! triples.empty( ) ) {
+ for ( auto & vec : triples ) {
+ std::cout << '(' ;
+ for ( auto num : vec ) {
+ std::cout << num << ' ' ;
+ }
+ std::cout << ")\n" ;
+ }
+ }
+ else {
+ std::cout << -1 << std::endl ;
+ }
+ return 0 ;
+ }
+}