public void Run2()
        {
            int[,] matrix = new[, ] {
                { 15, 30, 50, 70, 73 },
                { 35, 40, 100, 102, 120 },
                { 36, 42, 105, 110, 125 },
                { 46, 51, 106, 111, 130 },
                { 48, 55, 109, 140, 150 }
            };

            AssortedMethods.PrintMatrix(matrix);

            int rows    = matrix.GetLength(0);
            int columns = matrix.GetLength(1);

            int count            = 0;
            int littleOverTheMax = matrix[rows - 1, columns - 1] + 10;

            for (int i = 0; i < littleOverTheMax; i++)
            {
                Coordinate c = FindElement2(matrix, i);
                if (c != null)
                {
                    Console.WriteLine(i + ": (" + c.row + ", " + c.column + ")");
                    count++;
                }
            }
            Console.WriteLine("Found " + count + " unique elements.");
        }
Ejemplo n.º 2
0
Archivo: Q01_7.cs Proyecto: zs9912/ctci
        public void Run()
        {
            int nrows = 10;
            int ncols = 15;

            int[][] matrix1 = AssortedMethods.RandomMatrix(nrows, ncols, 0, 100);
            int[][] matrix2 = CloneMatrix(matrix1);

            AssortedMethods.PrintMatrix(matrix1);

            SetZeros(matrix1);
            SetZeros2(matrix2);

            Console.WriteLine();

            AssortedMethods.PrintMatrix(matrix1);
            Console.WriteLine();
            AssortedMethods.PrintMatrix(matrix2);

            if (MatricesAreEqual(matrix1, matrix2))
            {
                Console.WriteLine("Equal");
            }
            else
            {
                Console.WriteLine("Not Equal");
            }
        }
        public void Run1()
        {
            int M      = 10;
            int N      = 5;
            var matrix = new int[M, N];

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    matrix[i, j] = 10 * i + j;
                }
            }

            AssortedMethods.PrintMatrix(matrix);

            for (int i = 0; i < M; i++)
            {
                for (int j = 0; j < M; j++)
                {
                    int v = 10 * i + j;
                    Console.WriteLine(v + ": " + FindElement(matrix, v));
                }
            }
        }
Ejemplo n.º 4
0
        public void Run()
        {
            const int size = 3;

            int[][] matrix = AssortedMethods.RandomMatrix(size, size, 0, 9);
            AssortedMethods.PrintMatrix(matrix);
            Rotate(matrix, size);
            Console.WriteLine();
            AssortedMethods.PrintMatrix(matrix);
        }
Ejemplo n.º 5
0
        public override void Run()
        {
            const int numberOfRows    = 10;
            const int numberOfColumns = 15;
            var       matrix1         = AssortedMethods.RandomMatrix(numberOfRows, numberOfColumns, 0, 100);

            AssortedMethods.PrintMatrix(matrix1);
            SetZeros(matrix1);
            Console.WriteLine();
            AssortedMethods.PrintMatrix(matrix1);
        }
        public override void Run()
        {
            const int size = 3;

            var matrix = AssortedMethods.RandomMatrix(size, size, 0, 9);

            AssortedMethods.PrintMatrix(matrix);

            Rotate(matrix);
            Console.WriteLine();
            AssortedMethods.PrintMatrix(matrix);
        }
Ejemplo n.º 7
0
        public override void Run()
        {
            var matrix = new[, ]
            {
                { 1, 2, 3 },
                { 4, 5, 6 },
                { 7, 8, 9 }
            };

            AssortedMethods.PrintMatrix(matrix);

            Rotate(matrix, matrix.GetLength(0));
            Console.WriteLine();
            AssortedMethods.PrintMatrix(matrix);
        }
Ejemplo n.º 8
0
        public void Run()
        {
            const int numberOfRows    = 10;
            const int numberOfColumns = 15;
            var       matrix1         = AssortedMethods.RandomMatrix(numberOfRows, numberOfColumns, 0, 100);
            var       matrix2         = CloneMatrix(matrix1);

            AssortedMethods.PrintMatrix(matrix1);

            SetZeros(matrix1);
            SetZeros2(matrix2);

            Console.WriteLine();

            AssortedMethods.PrintMatrix(matrix1);
            Console.WriteLine();
            AssortedMethods.PrintMatrix(matrix2);

            Console.WriteLine(MatricesAreEqual(matrix1, matrix2) ? "Equal" : "Not Equal");
        }