Advertisement
Guest User

Untitled

a guest
Sep 15th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. class Program
  7. {
  8.     static void Main(string[] args)
  9.     {
  10.         Dictionary<String, int> allWords = new Dictionary<string, int>();
  11.  
  12.         String[] inputWords = Console.ReadLine().Split();
  13.  
  14.         for (int i = 0; i < inputWords.Length; i++)
  15.         {
  16.             String currentWord = inputWords[i];
  17.  
  18.             if (!allWords.ContainsKey(currentWord))
  19.             {
  20.                 allWords.Add(currentWord, 1);
  21.             }
  22.             else
  23.             {
  24.                 allWords[currentWord]++;
  25.             }
  26.         }
  27.  
  28.         StringBuilder result = new StringBuilder();
  29.  
  30.         foreach (var word in allWords)
  31.         {
  32.             for (int j = 0; j < word.Value; j++)
  33.             {
  34.                 result.Append(word.Key + " ");
  35.             }
  36.  
  37.             result.Length--;
  38.             result.Append("\n");
  39.         }
  40.  
  41.         Console.WriteLine(result.ToString().TrimEnd());
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement