Find Four points such that they form a square whose sides are parallel to x and y axes in C++

My Projects
Change Password
My Profile
Logout
Undo
Redo
Cut
Copy
Paste
Delete
Select All
Find
Find and Replace
Editor Theme
Crimson
Eclipse
Github
Solarized
Cobalt
krTheme
Monokai
Terminal
Textmate
Twilight
Vibrant Ink
Font Size
8px
9px
10px
11px
12px
13px
14px
15px
16px
17px
18px
20px
22px
24px
Tab Size
1
2
3
4
5
6
7
8
Show Invisible
Hide Invisible
Show Line Numbers
Hide Line Numbers
Ace Editor (Default)
Vim Editor
Emacs Editor
Open New Project
Save Project
Save As New Project
Share Project
Search Project
// C++ implemenataion of the above approach #include <bits/stdc++.h> using namespace std; // Determine the largest square void findLargestSquare1(long long int points1[][2], int n1){ // Used to map to store which points exist map<pair<long long int, long long int>, int> m1; // mark the available points for (int i = 0; i < n1; i++) { m1[make_pair(points1[i][0], points1[i][1])]++; } long long int side1 = -1, x1 = -1, y1 = -1; // Shows a nested loop to choose the opposite corners of square for (int i = 0; i < n1; i++) { // Used to remove the chosen point m1[make_pair(points1[i][0], points1[i][1])]--; for (int j = 0; j < n1; j++) { // Used to remove the chosen point m1[make_pair(points1[j][0], points1[j][1])]--; // Verify if the other two points exist if (i != j && (points1[i][0]-points1[j][0]) == (points1[i][1]-points1[j][1])){ if (m1[make_pair(points1[i][0], points1[j][1])] > 0 && m1[make_pair(points1[j][0], points1[i][1])] > 0) { // So if the square is largest then store it if (side1 < abs(points1[i][0] - points1[j][0]) || (side1 == abs(points1[i][0] -points1[j][0]) && ((points1[i][0] * points1[i][0] + points1[i][1] * points1[i][1]) < (x1 * x1 + y1 * y1)))) { x1 = points1[i][0]; y1 = points1[i][1]; side1 = abs(points1[i][0] - points1[j][0]); } } } // Used to add the removed point m1[make_pair(points1[j][0], points1[j][1])]++; } // Used to add the removed point m1[make_pair(points1[i][0], points1[i][1])]++; } // Used to display the largest square if (side1 != -1) cout << "Side of the square is : " << side1 << ", \npoints of the square are " << x1 << ", " << y1 << " " << (x1 + side1) << ", " << y1 << " " << (x1) << ", " << (y1 + side1) << " " << (x1 + side1) << ", " << (y1 + side1) << endl; else cout << "No such square" << endl; } //Driver code int main(){ int n1 = 6; // given points long long int points1[n1][2]= { { 2, 2 }, { 5, 5 }, { 4, 5 }, { 5, 4 }, { 2, 5 }, { 5, 2 } }; // Determine the largest square findLargestSquare1(points1, n1); return 0; }

Find Four points such that they form a square whose sides are parallel to x and y axes in C++ (GNU GCC v7.1.1)

Find Four points such that they form a square whose sides are parallel to x and y axes in C++ (GNU GCC v7.1.1) helps you to Edit, Run and Share your C++ Code directly from your browser. This development environment provides you version GNU GCC v7.1.1.

How to give program Input?

The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.

Keyboard Shortcuts

ShortcutDescription
⌘ + EnterRun the program
⌘ + SSave Project (Login Required)
⇧ + ⌘ + SSave As Project
⌘ + PNew Project
⌘ + GShare Project
⌘ + ZUndo Editing
⌘ + YRedo Editing
⌘ + ASelect All Text
⌘ + XCut Selected Text
⌘ + CCopy Selected Text
⌘ + VPaste Copied Text
⌘ + FSearch Text
⌘ + ⌥ + FReplace Text
ShortcutDescription
Ctrl + EnterRun the program
Ctrl + SSave Project
Shift + Ctrl + SSave As Project
Ctrl + GShare Project
Ctrl + ZUndo Editing
Ctrl + YRedo Editing
Ctrl + ASelect All Text
Ctrl + XCut Selected Text
Ctrl + CCopy Selected Text
Ctrl + VPaste Copied Text
Ctrl + FSearch Text
Ctrl + HReplace Text

Save C++ Project

You can save your C++ Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.

Share C++ Project

You can use this feature to share your C++ Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.

 Execute |  Beautify | Share