Character Repetition Count

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace CharacterRepetitionCount

{

    class Program

    {

        static void Main(string[] args)

        {

            string inputString = "";

            Console.Write("Enter a string: ");

            inputString = Console.ReadLine();

            if (inputString.Length != 0)

            {

                inputString = inputString.ToLower();

                char[] charArray = inputString.ToCharArray();

                Array.Sort(charArray);

                Console.WriteLine("Character repetitions: ");

                int count = 0;

                for (int i = 0; i < charArray.Length; i++)

                {

                    if (i == 0)

                    {

                        Console.Write(charArray[i] + " –> ");

                        count++;

                    }

                    else if (charArray[i] != charArray[i – 1])

                    {

                        Console.WriteLine(count);

                        count = 0;

                        Console.Write(charArray[i] + " –> ");

                        count++;

 

                    }

                    else

                    {

                        count++;

                    }

                }

                Console.WriteLine(count);

            }

        }

    }

}

 

Enter a string: She is very beautiful
Character repetitions:
  –> 3
a –> 1
b –> 1
e –> 3
f –> 1
h –> 1
i –> 2
l –> 1
r –> 1
s –> 2
t –> 1
u –> 2
v –> 1
y –> 1
Press any key to continue . . .

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s