Advertisement
gadjov

Homework: Max Sequence of Equal Elements

Apr 10th, 2016
1,201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MaxSequenceOfEqualElement
  8. {
  9.     class MaxSequenceOfEqualElement
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.             int[] counts = new int[nums.Max() + 1];
  15.             int equal = 0;
  16.             foreach (var num in nums)
  17.             {
  18.                 counts[num]++;
  19.             }
  20.             equal = nums[counts.Max()];
  21.             if (counts.Max() == 1)
  22.             {
  23.                 Console.WriteLine($"{nums.First()}");
  24.             }
  25.             else
  26.             {
  27.             for (int i = 0; i < counts.Max(); i++)
  28.             {
  29.                 Console.Write($"{equal} ");
  30.             }
  31.             }
  32.         }
  33.  
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement