本文整理汇总了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();
}
}
}