veronikaaa86

Count Numbers C# Desi

Feb 13th, 2018
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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 ConsoleApp7
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = Console.ReadLine()
  14.                 .Split(' ')
  15.                 .Select(int.Parse)
  16.                 .OrderBy(x => x)
  17.                 .ToList();
  18.  
  19.             int counter = 1;
  20.             //Console.WriteLine(string.Join(" ", numbers));
  21.             for (int i = 1; i < numbers.Count; i++)
  22.             {
  23.                
  24.                 if (numbers[0] == numbers[i])
  25.                 {
  26.                     counter++;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine($"{numbers[0]} -> {counter}");
  31.                     numbers[0] = numbers[i];
  32.                     counter = 1;
  33.                 }              
  34.             }
  35.             Console.WriteLine($"{numbers[0]} -> {counter}");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment