aboutsummaryrefslogtreecommitdiff
path: root/challenge-123/ulrich-rieke/cpp/ch-2.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-123/ulrich-rieke/cpp/ch-2.cpp')
-rw-r--r--challenge-123/ulrich-rieke/cpp/ch-2.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/challenge-123/ulrich-rieke/cpp/ch-2.cpp b/challenge-123/ulrich-rieke/cpp/ch-2.cpp
new file mode 100644
index 0000000000..c3ab8c3c04
--- /dev/null
+++ b/challenge-123/ulrich-rieke/cpp/ch-2.cpp
@@ -0,0 +1,45 @@
+#include <string>
+#include <iostream>
+#include <utility>
+#include <vector>
+#include <cmath>
+#include <set>
+using Point = std::pair<int, int> ;
+
+double computeDistance( const Point & p1 , const Point & p2 ) {
+ return std::sqrt( std::pow( static_cast<double>(p2.first - p1.first) ,
+ 2.0) + std::pow( static_cast<double>(p2.second - p1.second) ,
+ 2.0 ) ) ;
+}
+
+int main( ) {
+ std::vector<Point> points ;
+ int num = 0 ;
+ for ( int i = 0 ; i < 4 ; i++ ) {
+ Point p { 0 , 0 } ;
+ std::cout << "For " << i + 1 << ". point, enter x: \n" ;
+ std::cin >> num ;
+ p.first = num ;
+ std::cout << " and y: \n" ;
+ std::cin >> num ;
+ p.second = num ;
+ points.push_back( p ) ;
+ }
+ std::set<double> distances ;
+ for ( int i = 0 ; i < 3 ; i++ ) {
+ distances.insert( computeDistance( points[ i ] , points[ i++ ] )) ;
+ }
+ distances.insert( computeDistance( points[ 0 ] , points[ 3 ] )) ;
+ std::set<double> diagonals ;
+ diagonals.insert( computeDistance( points[ 0 ] , points[ 2 ] )) ;
+ diagonals.insert( computeDistance( points[ 1 ] , points[ 3 ] )) ;
+ if ( distances.size( ) == 1 && diagonals.size( ) == 1 ) {
+ std::cout << std::endl ;
+ std::cout << 1 << std::endl ;
+ }
+ else {
+ std::cout << std::endl ;
+ std::cout << 0 << std::endl ;
+ }
+ return 0 ;
+}