Advertisement
skipter

Numbers Count - List,Arrays,Dictionary...

Jul 11th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 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 _7.Count_Numbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var numbers = Console.ReadLine().Split(new char[] {' '},StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToList();
  14.             numbers.Sort();
  15.             numbers.Add(0);
  16.             var counter = 1;
  17.             for (int cnt = 0; cnt < numbers.Count - 1; cnt++)
  18.             {
  19.                 if (numbers[cnt] == numbers[cnt +1])
  20.                 {
  21.                     counter++;
  22.                 } else
  23.                 {
  24.                     Console.WriteLine($"{numbers[cnt]} -> {counter}");
  25.                     counter = 1;
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement