Advertisement
CuST0M1z3

FoundLetters

Jul 21st, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 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. /* Write a program that reads a string
  8.  * from the console and prints all different letters in the string along
  9.  * with information how many times each letter is found. */
  10.  
  11. class CheckLetters
  12. {
  13.     static void Main()
  14.     {
  15.         string text = "Telerik academy is the best, school is better, and you are beautiful";
  16.  
  17.         bool[] visited = new bool[text.Length];
  18.  
  19.  
  20.         for (int i = 0; i < text.Length; i++)
  21.         {
  22.             int count = 0;
  23.             if (visited[i] == false && char.IsLetter(text[i]))
  24.             {
  25.                 int index = text.IndexOf(text[i], 0);
  26.                 while (index != -1)
  27.                 {
  28.                     visited[index] = true;
  29.                     index = text.IndexOf(text[i], index + 1);
  30.                     count++;
  31.                 }
  32.                 Console.WriteLine("{0} - {1} times", text[i], count);
  33.             }                    
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement