Chessmaster

7. Count Numbers

Jun 26th, 2018
235
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.  
  5. namespace Practice
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             List<int> list = Console.ReadLine().Split().Select(int.Parse).ToList();
  12.  
  13.             list.Sort();
  14.  
  15.             int currentNumber = int.MinValue;
  16.             for (int i = 0; i < list.Count; i++)
  17.             {
  18.                 int counter = 0;
  19.                 for (int j = 0; j < list.Count; j++)
  20.                 {
  21.                     if (list[i] == list[j])
  22.                     {
  23.                         counter++;
  24.                     }
  25.                 }
  26.  
  27.                 if (list[i] != currentNumber)
  28.                 {
  29.                     currentNumber = list[i];
  30.                     Console.WriteLine("{0} -> {1}", currentNumber, counter);
  31.                 }
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment