当前位置: 首页>>代码示例>>C#>>正文


C# BigInteger.GetLength方法代码示例

本文整理汇总了C#中System.Numerics.BigInteger.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.GetLength方法的具体用法?C# BigInteger.GetLength怎么用?C# BigInteger.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Numerics.BigInteger的用法示例。


在下文中一共展示了BigInteger.GetLength方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main()
        {
            var firstSequenceLength = int.Parse(Console.ReadLine());
            var secondSequenceLength = int.Parse(Console.ReadLine());

            var firstSequence = new BigInteger[firstSequenceLength];
            var secondSequence = new BigInteger[secondSequenceLength];

            var allFirstNumbers = Console.ReadLine().Split(' ');
            var allSecondNumbers = Console.ReadLine().Split(' ');

            for (int i = 0; i < allFirstNumbers.Length; i++)
            {
                firstSequence[i] = BigInteger.Parse(allFirstNumbers[i]);
            }

            for (int i = 0; i < allSecondNumbers.Length; i++)
            {
                secondSequence[i] = BigInteger.Parse(allSecondNumbers[i]);
            }

            var toProcceed = false;

            var nodeMatrix = new BigInteger[firstSequenceLength, secondSequenceLength];

            for (int i = 0; i < nodeMatrix.GetLength(0); i++)
            {
                for (int j = 0; j < nodeMatrix.GetLength(1); j++)
                {
                    if (firstSequence[i] == secondSequence[j] && toProcceed)
                    {
                        nodeMatrix[i, j] = 1;
                        toProcceed = false;
                    }

                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    if (i == 0)
                    {
                        nodeMatrix[i, j] = nodeMatrix[i, j] + nodeMatrix[i, j - 1];
                        continue;
                    }

                    if (j == 0)
                    {
                        nodeMatrix[i, j] = nodeMatrix[i, j] + nodeMatrix[i - 1, j];
                        continue;
                    }

                    nodeMatrix[i, j] = nodeMatrix[i, j] + (new BigInteger[] { nodeMatrix[i - 1, j],nodeMatrix[i, j - 1] }).Max();
                }

                toProcceed = true;
            }

            Console.WriteLine(nodeMatrix[firstSequenceLength - 1, secondSequenceLength - 1]);
        }
开发者ID:antoanelenkov,项目名称:Telerik-Academy-HW,代码行数:60,代码来源:Program.cs

示例2: FillMatrix

        private static void FillMatrix(BigInteger[,] matrix)
        {
            var rows = matrix.GetLength(0);
            var cols = matrix.GetLength(1);

            matrix[rows - 1, 0] = 1;

            for (int i = rows - 2; i >= 0; i--)
            {
                matrix[i, 0] = matrix[i + 1, 0] * 2;
            }

            for (int i = 1; i < cols; i++)
            {
                matrix[rows - 1, i] = matrix[rows - 1, i - 1] * 2;
            }

            for (int row = rows - 2; row >= 0; row--)
            {
                for (int col = 1; col < cols; col++)
                {
                    matrix[row, col] = matrix[row + 1, col] + matrix[row, col - 1];
                }
            }
        }
开发者ID:tima-t,项目名称:Telerik-Academy,代码行数:25,代码来源:BigShiftMatrix.cs

示例3: FillField

        private static BigInteger[,] FillField(int rows, int cols)
        {
            BigInteger[,] matrix = new BigInteger[rows, cols];

            int index = 0;
            for (int i = matrix.GetLength(0) - 1; i >= 0; i--)
            {
                matrix[i, 0] = (BigInteger)Math.Pow(2, index);
                index++;
            }

            for (int i = 0; i < matrix.GetLength(1); i++)
            {
                matrix[matrix.GetLength(0) - 1, i] = (BigInteger)Math.Pow(2, i);
            }

            for (int row = matrix.GetLength(0) - 2; row >= 0; row--)
            {
                for (int col = 1; col < matrix.GetLength(1); col++)
                {
                    matrix[row, col] = matrix[row + 1, col] * 2;
                }
            }

            return matrix;
        }
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:26,代码来源:LoverOf3.cs

示例4: CalculatePownSum

        private static BigInteger CalculatePownSum(BigInteger[,] field, int[] codes)
        {
            int coef = Math.Max(field.GetLength(0), field.GetLength(1));
            BigInteger sum = 0;
            int currentRow = field.GetLength(0) - 1;
            int currentCol = 0;
            sum = field[currentRow, currentCol];
            field[currentRow, currentCol] = 0;

            for (int i = 0; i < codes.Length; i++)
            {
                int row = codes[i] / coef;
                int col = codes[i] % coef;

                if (row > currentRow)
                {
                    int times = row - currentRow;
                    for (int j = 0; j < times; j++)
                    {
                        currentRow++;
                        sum += field[currentRow, currentCol];
                        field[currentRow, currentCol] = 0;
                    }
                }
                else if (row < currentRow)
                {
                    int times = currentRow - row;
                    for (int j = 0; j < times; j++)
                    {
                        currentRow--;
                        sum += field[currentRow, currentCol];
                        field[currentRow, currentCol] = 0;
                    }
                }

                if (col > currentCol)
                {
                    int times = col - currentCol;
                    for (int j = 0; j < times; j++)
                    {
                        currentCol++;
                        sum += field[currentRow, currentCol];
                        field[currentRow, currentCol] = 0;
                    }
                }
                else if (col < currentCol)
                {
                    int times = currentCol - col;
                    for (int j = 0; j < times; j++)
                    {
                        currentCol--;
                        sum += field[currentRow, currentCol];
                        field[currentRow, currentCol] = 0;
                    }
                }
            }

            return sum;
        }
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:59,代码来源:LoverOf3.cs

示例5: FillField

        private static BigInteger[,] FillField(BigInteger[,] field)
        {
            for (int row = field.GetLength(0) - 1; row >= 0; row--)
            {
                for (int col = 0; col < field.GetLength(1); col++)
                {
                    field[row, col] = Power(2, field.GetLength(0) - 1 - row + col);
                }
            }

            return field;
        }
开发者ID:MarinaGeorgieva,项目名称:TelerikAcademy,代码行数:12,代码来源:LoverOfTwo.cs

示例6: Main

        static void Main()
        {
            string[] nm = Console.ReadLine().Split(' ');
            int n = int.Parse(nm[0]);
            int m = int.Parse(nm[1]);

            nm = Console.ReadLine().Split(' ');
            int fx = int.Parse(nm[0]);
            int fy = int.Parse(nm[1]);

            int k = int.Parse(Console.ReadLine());

            bool[,] matrix = new bool[fx + 1, fy + 1];

            for (int i = 0; i < k; i++)
            {
                nm = Console.ReadLine().Split(' ');
                int x = int.Parse(nm[0]);
                int y = int.Parse(nm[1]);

                if (x <= fx && y <= fy)
                {
                    matrix[x, y] = true;
                }
            }

            BigInteger[,] count = new BigInteger[fx + 1, fy + 1];
            count[0, 0] = 1;

            for (int col = 1; col < count.GetLength(1); col++)
            {
                count[0, col] = matrix[0, col] ? 0 : count[0, col - 1];
            }

            for (int row = 1; row < count.GetLength(0); row++)
            {
                count[row, 0] = matrix[row, 0] ? 0 : count[row - 1, 0];
            }

            for (int row = 1; row < count.GetLength(0); row++)
            {
                for (int col = 1; col < count.GetLength(1); col++)
                {
                    count[row, col] = matrix[row, col] ? 0 : count[row - 1, col] + count[row, col - 1];
                }
            }

            Console.WriteLine(count[fx, fy]);
        }
开发者ID:tvmarinov,项目名称:Homework,代码行数:49,代码来源:Program.cs

示例7: Main

        static void Main(string[] args)
        {
            int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = nm[0];
            int m = nm[1];

            int[] fxy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int foodX = fxy[0];
            int foodY = fxy[1];

            bool[,] isEnemy = new bool[n+1, m+1];
            int enemiesCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < enemiesCount; i++)
            {
                int[] exy = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int enemyX = exy[0];
                int enemyY = exy[1];

                isEnemy[enemyX, enemyY] = true;
            }

            BigInteger[,] dp = new BigInteger[n, m];
            for (int i = 0; i < dp.GetLength(0); i++)
            {
                dp[i, 0] = 1;
            }

            for (int j = 0; j < dp.GetLength(1); j++)
            {
                dp[0, j] = 1;
            }

            for (int i = 1; i < dp.GetLength(0); i++)
            {
                for (int j = 1; j < dp.GetLength(1); j++)
                {
                    dp[i, j] = isEnemy[i, j] ? 0 : dp[i - 1, j] + dp[i, j - 1];
                }
            }

            Console.WriteLine(dp[foodX, foodY]);
        }
开发者ID:RvnDrk,项目名称:TelerikAcademy-2016-2017,代码行数:43,代码来源:Program.cs

示例8: Main

        static void Main()
        {
            string input = Console.ReadLine();
            BigInteger[,] matrix = new BigInteger[input.Length + 1, input.Length + 2];
            matrix[0, 0] = 1;
            for (int row = 0; row < input.Length; row++)
            {
                for (int col = 0; col < input.Length+2; col++)
                {
                    if (input[row] == '(')
                    {
                        if (col != 0)
                        {
                            matrix[row + 1, col] = matrix[row, col - 1];
                        }
                        else
                        {
                            matrix[row + 1, col] = 0;
                        }
                    }
                    else if (input[row] == ')')
                    {
                        if (col != input.Length+1 )
                        {
                            matrix[row + 1, col] = matrix[row, col + 1];
                        }
                        else
                        {
                            matrix[row + 1, col] = 0;
                        }
                    }
                    else
                    {
                        if (col == 0)
                        {
                            matrix[row + 1, col] = matrix[row, col + 1];
                        }
                        else if (col ==input.Length+1 )
                        {
                            matrix[row + 1, col] = matrix[row, col - 1];
                        }
                        else
                        {
                            matrix[row + 1, col] = matrix[row, col + 1] + matrix[row, col - 1];
                        }
                    }
                }
            }

            Console.WriteLine(matrix[matrix.GetLength(0) - 1 ,0]);
        }
开发者ID:purlantov,项目名称:TelerikAcademy-4,代码行数:51,代码来源:Program.cs

示例9: Main

        static void Main(string[] args)
        {
            List<BigInteger> myList = new List<BigInteger>();

            while (true)
            {
                BigInteger currNumber = BigInteger.Parse(Console.ReadLine());

                if (currNumber == -1)
                {
                    break;
                }
                else
                {
                    myList.Add(currNumber);
                }
            }

            BigInteger[,] matrix = new BigInteger[myList.Count, 32];

            for (int i = 0; i < myList.Count; i++)
            {
                BigInteger currentNumber = myList[i];

                for (int j = 31; j >= 0; j--)
                {
                    matrix[i, j] = (currentNumber >> j) & 1;
                }
            }

            for (int i = 0; i < myList.Count; i++)
            {
                int startIndex = 0;

                for (int j = 31; j > 0; j--)
                {
                    if (matrix[i, j] == 1 && matrix[i, j - 1] == 0)
                    {
                        startIndex = j;
                        matrix[i, startIndex] = 2;
                        for (int k = startIndex; k > 0; k--)
                        {
                            if (matrix[i, k] == 0 && matrix[i, k - 1] == 1)
                            {
                                matrix[i, k - 1] = 3;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < myList.Count; i++)
            {
                int start = -1;
                int end = -1;
                for (int j = 31; j > 0; j--)
                {
                    if (matrix[i, j] == 2)
                    {
                        start = j;

                    }
                    if (matrix[i, j] == 3)
                    {
                        end = j;
                    }

                    if (start >= 0 && end >= 0)
                    {
                        for (int y = end + 1; y < start; y++)
                        {
                            matrix[i, y] = 5;
                        }
                    }
                }
            }

            for (int i = 0; i < myList.Count; i++)
            {
                for (int j = 31; j > 0; j--)
                {
                    if (matrix[i, j] == 1 || matrix[i, j] == 2 || matrix[i, j] == 3)
                    {
                        matrix[i, j] = 0;
                    }
                    else if (matrix[i, j] == 5)
                    {
                        matrix[i, j] = 1;
                    }
                }
            }

            StringBuilder result = new StringBuilder();
            for (int i = 0; i < matrix.GetLength(0); i++)
            {

                for (int j = matrix.GetLength(1) - 1; j >= 0; j--)
                {
                    result.Append(matrix[i, j]);
                }
//.........这里部分代码省略.........
开发者ID:nnaidenov,项目名称:TelerikAcademy,代码行数:101,代码来源:Neurons.cs


注:本文中的System.Numerics.BigInteger.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。