FRom hackerrank.

Roy wanted to increase his typing speed for programming contests. His friend suggested that he type the sentence "The quick brown fox jumps over the lazy dog" repeatedly. This sentence is known as a pangram because it contains every letter of the alphabet.
After typing the sentence several times, Roy became bored with it so he started to look for other pangrams.
Given a sentence, determine whether it is a pangram. Ignore case.

Solution in C# -

class Solution {
    static string pangrams(string s) {
        s = s.ToLower();
        List<char> alphabets = new List<char>();
        for(int i=0; i<s.Length; i++)
            if(!alphabets.Contains(s[i]))
                alphabets.Add(s[i]);
        if(alphabets.Count == 27)
        return "pangram";
        else
        return "not pangram";
    }
    static void Main(string[] args) {
        TextWriter textWriter = new StreamWriter(@System.Environment.GetEnvironmentVariable("OUTPUT_PATH"), true);
        string s = Console.ReadLine();
        string result = pangrams(s);
        textWriter.WriteLine(result);
        textWriter.Flush();
        textWriter.Close();
    }
}

Post a Comment

Previous Post Next Post