Bhavya

Code -> Break -> Fix -> Blog

Print the alphabets which are not part of a given string (C#)

Leave a comment

Problem Statement: Print the alphabets which are not part of a given string.

Solution


var alpha = new Dictionary<char, bool>();
alpha.Add('a', false);
alpha.Add('b', false);
alpha.Add('c', false);
alpha.Add('d', false);
alpha.Add('e', false);
alpha.Add('f', false);
alpha.Add('g', false);
alpha.Add('h', false);
alpha.Add('i', false);
alpha.Add('j', false);
alpha.Add('k', false);
alpha.Add('l', false);
alpha.Add('m', false);
alpha.Add('n', false);
alpha.Add('o', false);
alpha.Add('p', false);
alpha.Add('q', false);
alpha.Add('r', false);
alpha.Add('s', false);
alpha.Add('t', false);
alpha.Add('u', false);
alpha.Add('v', false);
alpha.Add('w', false);
alpha.Add('x', false);
alpha.Add('y', false);
alpha.Add('z', false);

var inputString = "bhavyajshah";

foreach(char ch in inputString.ToLower())
alpha[ch] = true;

foreach (var item in alpha)
{
if (item.Value != true)
Console.WriteLine(item.Key);
}

Advertisements

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