kirililchev3

Count Numbers - Lists

Jun 9th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace P07_Count_Numbers
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.            
  12.  
  13.             List<int> numbers = Console.ReadLine()
  14.                 .Split()
  15.                 .Select(int.Parse)
  16.                 .ToList();
  17.  
  18.             numbers.Sort();
  19.  
  20.             int count = 1;
  21.             int curr = numbers[0];
  22.             for (int i = 1; i < numbers.Count; i++)
  23.             {
  24.                 if (curr == numbers[i])
  25.                 {
  26.                     count++;
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine($"{curr} -> {count}");
  31.                     count = 1;
  32.                     curr = numbers[i];
  33.                 }
  34.             }
  35.             Console.WriteLine($"{curr} -> {count}");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment