Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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 DZNEW
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             List<String> list = new List<String>();
  14.  
  15.             String str = "111 111 222 222 222 333 333 333 333 333";
  16.  
  17.             String[] arr = str.Split(' ');
  18.  
  19.             Dictionary<String, int> collection = new Dictionary<String, int>();
  20.  
  21.  
  22.             foreach (String element in arr)
  23.             {
  24.                 list.Add(element);
  25.             }
  26.  
  27.             int count = 0;
  28.  
  29.             for(int i = 0; i < list.Count; i++)
  30.             {
  31.                 count = 0;
  32.                 for(int j = 0; j < list.Count; j++)
  33.                 {
  34.                     if(list[i] == list[j])
  35.                     {
  36.                         count++;
  37.                     }
  38.                 }
  39.  
  40.                 if (!collection.ContainsKey(list[i]))
  41.                 {
  42.                     collection.Add(list[i], count);
  43.                 }
  44.                
  45.             }
  46.  
  47.  
  48.            foreach(var element in collection)
  49.            {
  50.                Console.WriteLine("{0}  -  {1}", element.Key, element.Value);
  51.            }
  52.            
  53.  
  54.  
  55.         }
  56.     }
  57.  
  58.    
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement