grubcho

Number counts dump way

Jun 23rd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 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. //Read a list of integers in range [0…1000] and print them in ascending order along with their number of occurrences.
  7. namespace count_numbers
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> nums = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.             List<int> occurances = new List<int>();
  15.             for (int i = 0; i < 1000; i++)
  16.             {
  17.                 occurances.Add(0);
  18.             }
  19.  
  20.             foreach (var num in nums)
  21.             {
  22.                 occurances[num]++;
  23.             }
  24.             for (int num = 0; num < occurances.Count; num++)
  25.             {
  26.                 if (occurances[num] > 0)
  27.                 {
  28.                     Console.WriteLine(num + " -> " + occurances[num]);
  29.                 }
  30.                    
  31.             }                
  32.         }
  33.     }
  34. }
Add Comment
Please, Sign In to add comment