SHARE
TWEET

Untitled

a guest Jun 9th, 2017 131 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace arrays
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             int count = 1;
  15.             int currentIndex = 0;
  16.             int bestIndex = 0;
  17.             int bestcount = 0;
  18.             for (int i = 1; i < arr.Length; i++)
  19.             {
  20.                 if (arr[i] == arr[currentIndex])
  21.                 {
  22.                     count++;
  23.                     if (count>bestcount)
  24.                     {
  25.                         bestcount = count;
  26.                         bestIndex = currentIndex;
  27.                     }
  28.  
  29.                 }
  30.                 else
  31.                 {
  32.                     count--;
  33.                 }
  34.                 if (count == 0)
  35.                 {
  36.                     currentIndex = i;
  37.                     count = 1;
  38.                 }
  39.             }
  40.  
  41.             int mostFreq = arr[bestIndex];
  42.             Console.WriteLine(mostFreq);
  43.         }
  44.     }
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top