CountOfRightAngle.cs

CSharp · Console

/Program.cs

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));
	}
}
;