Advertisement
stefan1919

Longest Area in Array

Aug 22nd, 2015
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 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 ConsoleApplication4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int index = 1;
  15.             List<string> array = new List<string>();
  16.             string input = Console.ReadLine();
  17.             array.Add(input);
  18.             while (index < n)
  19.             {
  20.                 input = Console.ReadLine();
  21.                 array.Add(input);
  22.                 index++;
  23.             }
  24.            
  25.             string currentBestString = array[0];
  26.             int currentBestNumber = 0;
  27.             int counter = 0;// counts the occurences
  28.             int countNumbers = 0;// counts the number of the numbers
  29.             while (countNumbers < n)
  30.             {
  31.                 string m = array[countNumbers];
  32.                 for (int i = 0; i < n; i++)
  33.                 {
  34.                     if (m == array[i])
  35.                     {
  36.                         counter++;
  37.                     }
  38.                 }
  39.                 if (counter > currentBestNumber)
  40.                 {
  41.                     currentBestNumber = counter;
  42.                     currentBestString = m;
  43.                 }
  44.                 counter = 0;
  45.                 countNumbers++;
  46.             }
  47.             Console.WriteLine(currentBestNumber);
  48.             int writerConsole = 0;
  49.             do
  50.             {
  51.                 Console.WriteLine(currentBestString);
  52.                 writerConsole++;
  53.             } while (writerConsole < currentBestNumber);
  54.  
  55.            
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement