Advertisement
Guest User

Count Symbols

a guest
Sep 19th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         string words = Console.ReadLine();
  8.         char[] arr = words.ToCharArray(); Array.Sort(arr);
  9.         int counter = 0;
  10.         for (int i = 0; i < arr.Length - 1; i++)
  11.         {
  12.             counter++;
  13.             if (arr[i] != arr[i + 1])
  14.             {
  15.                 Console.WriteLine("{0}: {1} time/s", arr[i], counter);
  16.                 counter = 0;
  17.             }
  18.            
  19.             if (i == arr.Length - 2)
  20.             {
  21.                 Console.WriteLine("{0}: {1} time/s", arr[i + 1], ++counter);
  22.             }
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement