Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class MostFrequentNumber
- {
- static void Main()
- {
- int[] arr = { 1, 1, 55, 55, 1,55,55 };
- List<int> list = new List<int>();
- int appearance = 1;
- int bestAppearance = 0;
- int value = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- if (list.Contains(arr[i]))
- {
- continue;
- }
- for (int j = i + 1; j < arr.Length; j++)
- {
- if (arr[i] == arr[j])
- {
- appearance++;
- if (appearance > bestAppearance)
- {
- bestAppearance = appearance;
- value = arr[i];
- }
- }
- }
- //if (appearance > bestAppearance)
- //{
- // bestAppearance = appearance;
- // value = arr[i];
- //}
- appearance = 1;
- list.Add(arr[i]); //добавям ги в листа и проверявам за да не се повтаря търсенето
- }
- Console.Write("Best times -> " + bestAppearance);//4
- Console.WriteLine(" Value -> " + value);//5
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment