Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- // Arr.GetLength(0) - gets the length of the first dimension. Arr.GetLength(1) - gets the length of the second dimension. Arr.Length - gets the length of all objects. (Dimension A * Dimension B)
- namespace Bagrut2010_Targil9
- {
- class Program
- {
- static void Main(string[] args)
- {
- int SameDiagonals=0;
- int[,] Arr = new int[4, 4];
- Console.WriteLine(Arr.Length);
- Random rand = new Random(); // Not requested in the exam, just for testing purposes
- for (int a = 0; a < Arr.GetLength(0); a++) // ^
- { // ^
- for (int b = 0; b < Arr.GetLength(1); b++) // ^
- { // ^
- Arr[a, b] = rand.Next(0, 2); // ^
- Console.Write("{0,6}", Arr[a, b]); // ^
- } // ^
- Console.WriteLine(); Console.WriteLine(); // ^
- }
- for (int i = 0; i < Arr.GetLength(0); i++)
- {
- for (int p = 0; p < Arr.GetLength(1); p++)
- {
- if (IsExist(Arr, i, p) == true)
- {
- if (IsSame(Arr, i, p) == true)
- SameDiagonals++;
- }
- }
- }
- Console.WriteLine("There are " + SameDiagonals + " diagonls whose length is 3 and are equal to 1.");
- }
- static bool IsExist(int[,] Arr,int x, int y) // x=horizontal row y=vertical column INDEXES
- { // 36x52 : 36 rows and 52 columns
- if (x <=Arr.GetLength(0) - 3 &&y <=Arr.GetLength(1) - 3)
- return true;
- else return false;
- }
- static bool IsSame(int[,] array, int x, int y)
- {
- if (IsExist(array,x, y) == true)
- {
- if(array[x,y]==1&&array[x+1,y+1]==1&&array[x+2,y+2]==1)
- return true;
- else return false;
- }
- else return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment