-
-
Save unilecs/7b7feaa30b13ac35249ffb23656d7dfe to your computer and use it in GitHub Desktop.
Задача 70: Прямой угол
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public class Program | |
{ | |
public class Point | |
{ | |
public Point(int x, int y) | |
{ | |
X = x; | |
Y = y; | |
} | |
public int X { get; set; } | |
public int Y { get; set; } | |
} | |
public static int Scalar(Point first, Point second) | |
{ | |
return first.X * second.X + first.Y * second.Y; | |
} | |
public static int CountOfRightAngle(Point bottomLeft, Point topLeft, Point topRight, Point bottomRight) | |
{ | |
Point[] points = new Point[6]; | |
points[0] = bottomLeft; | |
points[1] = topLeft; | |
points[2] = topRight; | |
points[3] = bottomRight; | |
points[4] = points[0]; | |
points[5] = points[1]; | |
int count = 0; | |
for (int i = 0; i < 4; i++) | |
{ | |
var firstPoint = new Point(points[i + 1].X - points[i].X, points[i + 1].Y - points[i].Y); | |
var secondPoint = new Point(points[i + 2].X - points[i + 1].X, points[i + 2].Y - points[i + 1].Y); | |
if (Scalar(firstPoint, secondPoint) == 0) | |
{ | |
count++; | |
} | |
} | |
return count; | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
int result = CountOfRightAngle(new Point(-1, 0), new Point(-1, 4), new Point(2, 4), new Point(4, 1)); | |
Console.WriteLine(string.Format("Answer = {0}", result)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment