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


C# BigInteger.Sort方法代码示例

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


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

示例1: Problem62

        /**
         * The cube, 41063625 (345^3), can be permuted to produce two other cubes: 56623104 (384^3) and 66430125 (405^3).
         * In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.
         *
         * Find the smallest cube for which exactly five permutations of its digits are cube.
         */
        public void Problem62()
        {
            var cubes = new HashSet<String>();

            var maxCubeRoot = new BigInteger(10000);

            for (var c = new BigInteger(1); c <= maxCubeRoot; c++)
            {
                cubes.Add(_lib.ToThePower(c, 3).ToString());
            }

            var maxCube = _lib.ToThePower(maxCubeRoot, 3);

            Console.Out.WriteLine("Number of Cubes: {0}, Max Cube: {1}", cubes.Count, maxCube);
            Console.Out.WriteLine();

            var sortedCubes = new Dictionary<String, List<String>>();

            foreach (var cube in cubes)
            {
                var c = cube.ToCharArray().ToList().Select(e => int.Parse(e.ToString(CultureInfo.InvariantCulture))).ToList();
                c.Sort();

                var s = "";

                foreach (var i in c)
                {
                    s += i.ToString(CultureInfo.InvariantCulture);
                }

                if (sortedCubes.ContainsKey(s))
                {
                    sortedCubes[s].Add(cube);
                }
                else
                {
                    sortedCubes.Add(s, new List<string> { cube });
                }

            }

            foreach (var sortedCube in sortedCubes)
            {
                if (sortedCube.Value.Count == 5)
                {
                    Console.Out.WriteLine("base Key: {0}", sortedCube.Key);
                    Console.Out.WriteLine();
                    Console.Out.WriteLine("Sorted Big Integers : ");
                    Console.Out.WriteLine();

                    var cus = new List<BigInteger>();

                    sortedCube.Value.ForEach(x => cus.Add(BigInteger.Parse(x)));

                    cus.Sort();

                    cus.ForEach(e => Console.Out.WriteLine(e));

                    Console.Out.WriteLine();

                    for (var c = new BigInteger(1); c <= maxCubeRoot; c++)
                    {
                        if (_lib.ToThePower(c, 3).Equals(cus[0]))
                        {
                            Console.Out.WriteLine("Cube root is : {0}", c);
                        }
                    }
                    //answer is 127035954683

                    Console.Out.WriteLine();

                }
            }
        }
开发者ID:pgtaggart,项目名称:ElrC,代码行数:80,代码来源:CombinationProblems.cs


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