public static void Main(string[] args) { int[] numbers = FunctionsCollection.ReadIntListInRangeUptoEmptyLine().ToArray(); Dictionary <int, int> numbersCount = FunctionsCollection.GetNumbersCount(numbers); int?majorant = FindMajorant(numbersCount, numbers.Length); if (majorant == null) { Console.WriteLine("There is no majorant of that sequence!"); } else { Console.WriteLine("The majorant is: {0}", majorant); } }
public static void Main(string[] args) { Console.WriteLine("We expect numbers in the range [0 .. 1000]"); int[] numbers = FunctionsCollection.ReadIntListInRangeUptoEmptyLine(0, 1000).ToArray(); Dictionary <int, int> numbersCount = FunctionsCollection.GetNumbersCount(numbers); Console.WriteLine("The number occurances count is:"); foreach (KeyValuePair <int, int> numberCount in numbersCount) { if (numberCount.Value == 1) { Console.WriteLine("{0} -> {1} time", numberCount.Key, numberCount.Value); } else { Console.WriteLine("{0} -> {1} times", numberCount.Key, numberCount.Value); } } }
private static LinkedList <int> RemoveOddOccuringNumbers(LinkedList <int> numbers) { Dictionary <int, int> occurances = FunctionsCollection.GetNumbersCount(numbers); LinkedListNode <int> node = numbers.First; while (node != null) { LinkedListNode <int> next = node.Next; if (occurances[node.Value] % 2 != 0) { numbers.Remove(node); } node = next; } return(numbers); }