Connection Status:
Competition Arena > IsItASquare
SRM 668 · 2015-08-31 · by zxqfl · Geometry
Class Name: IsItASquare
Return Type: String
Method Name: isSquare
Arg Types: (vector<int>, vector<int>)
Problem Statement

Problem Statement

It's a bird! It's a plane! No, it's a square in a plane! Wait, is it really a square?

There are four distinct points in the plane. You are given their coordinates in the int[]s x and y: for each i between 0 and 3, inclusive, there is a point at (x[i], y[i]).

Return "It's a square" (quotes for clarity) if the four points are the vertices of a square. Otherwise, return "Not a square".

Constraints

  • x will contain 4 elements.
  • y will contain 4 elements.
  • Each element of x will be between 0 and 10,000, inclusive.
  • Each element of y will be between 0 and 10,000, inclusive.
  • The four points described by x and y will be distinct.
Examples
0)
{0, 0, 2, 2}
{0, 2, 0, 2}
Returns: "It's a square"
1)
{0, 1, 5, 6}
{1, 6, 0, 5}
Returns: "It's a square"

Note that the sides of the square do not have to be parallel to the coordinate axes. Also note that the order in which the points are given does not have to be the same as the order in which you would encounter them when following the boundary of the square.

2)
{0, 0, 7, 7}
{0, 3, 0, 3}
Returns: "Not a square"
3)
{0, 5000, 5000, 10000}
{5000, 0, 10000, 5000}
Returns: "It's a square"
4)
{1, 2, 3, 4}
{4, 3, 2, 1}
Returns: "Not a square"

Submissions are judged against all 47 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class IsItASquare with a public method string isSquare(vector<int> x, vector<int> y) · 47 test cases · 2 s / 256 MB per case

Submitting as anonymous