Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.59 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. using System.Numerics;
  7.  
  8.  
  9. namespace Revision
  10. {
  11.     class ContinueTest
  12.     {
  13.         static void Main()
  14.         {
  15.             string input = Console.ReadLine();
  16.             string[] inputSplit = input.Split(' ');
  17.  
  18.             int[] numbers = new int[inputSplit.Length];
  19.             for (int i = 0; i < numbers.Length; i++)
  20.             {
  21.                 numbers[i] = int.Parse(inputSplit[i]);
  22.             }
  23.  
  24.             int count = 1;
  25.             int frequent = 0;
  26.             int highestCount = 0;
  27.             int mostFrequent = 0;
  28.             for (int k = 0; k < numbers.Length; k++)
  29.             {
  30.                 for (int l = k + 1; l < numbers.Length; l++)
  31.                 {
  32.                     if (numbers[k] == numbers[l])
  33.                     {
  34.                         count++;
  35.                         frequent = numbers[k];
  36.                         if (count > highestCount)
  37.                         {
  38.                             highestCount = count;
  39.                             mostFrequent = frequent;
  40.                         }
  41.                     }
  42.                     else
  43.                     {
  44.                         count = 1;
  45.                     }
  46.                 }
  47.                 count = 1;
  48.             }
  49.             if (mostFrequent == 0)
  50.             {
  51.                 Console.WriteLine("{0}", numbers[0]);
  52.             }
  53.             else
  54.             {
  55.                 Console.WriteLine(mostFrequent);
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement