Advertisement
Teodor92

DifferentLetters.cs

Jan 24th, 2013
418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class DifferentLetters
  6. {
  7.     public static void Main()
  8.     {
  9.         string[] specialSigns = { " ", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "-", "_", "+" };
  10.  
  11.         string input = Console.ReadLine();
  12.  
  13.         for (int i = 0; i < specialSigns.Length; i++)
  14.         {
  15.             input = input.Replace(specialSigns[i], string.Empty);
  16.         }
  17.  
  18.         Dictionary<char, int> allLetters = new Dictionary<char, int>();
  19.  
  20.         for (int i = 0; i < input.Length; i++)
  21.         {
  22.             if (allLetters.ContainsKey(input[i]))
  23.             {
  24.                 allLetters[input[i]]++;
  25.             }
  26.             else
  27.             {
  28.                 allLetters.Add(input[i], 1);
  29.             }
  30.         }
  31.  
  32.         var sortedLetters = allLetters.OrderBy(x => x.Key);
  33.         foreach (var item in sortedLetters)
  34.         {
  35.             Console.WriteLine("Letter --> {0} - Number --> {1}", item.Key, item.Value);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement