Exemple #1
0
        static void Main(string[] args)
        {
            int numberOfRows    = ReadInt("number of rows is:");
            int numberOfColumns = ReadInt("number of columns is: ");

            int[,] matrix = CreateRandomMatrix(numberOfRows, numberOfColumns);
            int index = 0;

            int[] arrayOfFirstLine = GetCurrentSortedArray(index, matrix, numberOfColumns);
            NumbersOflineAndHowManyTimesItIsMet[] indexLineAndNumberOfsimilarities = new NumbersOflineAndHowManyTimesItIsMet[numberOfRows];
            int countOfSimilarities = 0;

            for (int i = 1; i < numberOfRows; i++)
            {
                int[] arrayOfCurrentLine = GetCurrentSortedArray(i, matrix, numberOfColumns);
                countOfSimilarities = FindSimilarities(arrayOfFirstLine, arrayOfCurrentLine);
                indexLineAndNumberOfsimilarities[i - 1] = new NumbersOflineAndHowManyTimesItIsMet(i, countOfSimilarities);
                Console.WriteLine($"number of line {indexLineAndNumberOfsimilarities[i-1].IndexOfLine + 1} and number of similarities {indexLineAndNumberOfsimilarities[i-1].NumberOfSimilarities}");
            }
            int countOfLines = 0;

            for (int i = 0; i < numberOfRows - 1; i++)
            {
                if (indexLineAndNumberOfsimilarities[i].NumberOfSimilarities >= numberOfColumns / 2)
                {
                    countOfLines++;
                }
            }
            Console.WriteLine($"number of similar lines is {countOfLines}");
            Console.ReadKey();
        }
Exemple #2
0
        static NumbersOflineAndHowManyTimesItIsMet[] RewriteNumberOfCoinsidingNumbersAndItsLine(NumbersOflineAndHowManyTimesItIsMet[] array, NumbersOflineAndHowManyTimesItIsMet newElement)
        {
            int arrayLength = 0;

            if (array != null)
            {
                arrayLength = array.Length;
            }
            NumbersOflineAndHowManyTimesItIsMet[] result = new NumbersOflineAndHowManyTimesItIsMet[arrayLength + 1];
            for (int j = 0; j < arrayLength; j++)
            {
                result[j] = array[j];
            }
            result[result.Length - 1] = newElement;
            return(result);
        }