svetlozar_kirkov

Sort chars in text and count them (Exercise)

Oct 11th, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5.  
  6. namespace ConsoleTests
  7. {
  8.     class ConsoleTests
  9.     {
  10.         static void Main()
  11.         {
  12.             string text = Console.ReadLine();
  13.             char[] characters = text.ToLower().ToCharArray();
  14.             Array.Sort(characters, StringComparer.InvariantCulture);
  15.             int count = 1;
  16.             for (int i = 0; i < characters.Length && i+1 < characters.Length; i++)
  17.             {
  18.                 if (Char.IsLetter(characters[i]))
  19.                 {
  20.                     if (characters[i] == characters[i + 1])
  21.                     {
  22.                         count++;
  23.                     }
  24.                     else
  25.                     {
  26.                         Console.WriteLine("{0} --> {1}", characters[i], count);
  27.                         count = 1;
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment