Advertisement
NadyaMisheva

razpredelyane na chisla

Feb 23rd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. public class Program
  4. {
  5.     public static void Main()
  6.     {
  7.         int[] numbers = {1, 5, 15, 5, 1, 1, 5, 15};
  8.         Dictionary<int, int> st = new Dictionary<int, int>();
  9.         foreach(int num in numbers)
  10.         {
  11.             if(st.ContainsKey(num))
  12.             {
  13.                 st[num]++;
  14.             }
  15.             else
  16.             {
  17.                 st[num]= 1;
  18.             }
  19.         }
  20.          foreach( var el in st)
  21.          {
  22.             Console.WriteLine("{0} -> {1}", el.Key, el.Value);
  23.          }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement