Question 5

Code for Pangram Checking

Pangram Checking

Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.

Examples : The quick brown fox jumps over the lazy dog ” is a Pangram [Contains all the characters from ‘a’ to ‘z’]
“The quick brown fox jumps over the dog” is not a Pangram [Doesn’t contains all the characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing]

We create a mark[] array of Boolean type. We iterate through all the characters of our string and whenever we see a character we mark it. Lowercase and Uppercase are considered the same. So ‘A’ and ‘a’ are marked in index 0 and similarly ‘Z’ and ‘z’ are marked in index 25.

After iterating through all the characters we check whether all the characters are marked or not. If not then return false as this is not a pangram else return true.

Code for checking whether a string is Pangram or not

46 comments on “Question 5”


  • Harsha

    The given testcase is wrong
    Actually the given string is not a pangram as it does not have “u” in the input
    Python code for the above problem is:
    n=input()
    n=n.lower()
    n=n.replace(” “,””)
    A=”qwertyuiopasdfghjklzxcvbnm”
    for i in A:
    if i not in n:
    print(“Not a pangram”)
    break
    else:
    print(“Pangram”)


  • Nageswar

    x = input()
    a = x.upper()
    b = []
    for i in range(0, 91):
    b.append(0)
    for i in a:
    if i == ” “:
    continue
    b[ord(i)] = 1
    b = b[65:91]
    if 0 in b:
    print(x, “is not a program”)
    else:
    print(x, “is a program”)


  • Bireswar

    import java.util.*;
    public class digital5 {
    public static void main(String ars[])
    {
    Scanner sc=new Scanner(System.in);
    System.out.println(“Enter a string “);
    String str=sc.nextLine();
    String str1=str.toUpperCase();
    boolean success = true;
    for(char i=’A’;i<='Z';i++)
    {
    if(!str1.contains(String.valueOf(i)))
    {
    success=false;
    break;
    }
    }
    if(success)
    System.out.println("Found all character");
    else
    System.out.println("Not found all character");
    }

    }


  • MAHIN

    JAVA SOLUTION:

    import java.util.Scanner;
    class Main{
    public static void main(String[]args){
    Scanner input = new Scanner(System.in);
    String s = input.nextLine();
    Set check = new HashSet();
    for(int i=0;i<sentence.length();i++){
    char c = (sentence.charAt(i));
    check.add(c);
    }
    if(check.size()==26)
    return true;
    return false;
    }
    }


  • culbgaming12

    //C++ Solution

    #include
    using namespace std;

    bool pangram_checking(string s)
    {
    bool mark[26];

    for (int i = 0; i < s.length(); i++)
    {
    char t = tolower(s[i]);
    int j = (int)t – 97;
    if (s[i] != ' ' && mark[j] != true)
    {
    mark[j] = true;
    }
    }

    for (int i = 0; i < 26; i++)
    {
    if (mark[i] == false)
    {
    return false;
    }
    }

    return true;
    }

    int main()
    {
    string s;

    getline(cin, s);

    bool ans = pangram_checking(s);

    if (ans)
    {
    cout << "The given string is a panagram" << endl;
    }

    else
    {
    cout << "The given string is not a panagram" << endl;
    }

    return 0;
    }


  • ANKIT

    #include
    using namespace std;

    // Returns true if the string is
    // pangram else false
    bool checkPangram(string& str)
    {
    // Create a hash table to mark
    // the characters
    // present in the string
    vector mark(26, false);

    // For indexing in mark[]
    int index;

    // Traverse all characters
    for (int i = 0; i < str.length(); i++) {

    // If uppercase character,
    // subtract 'A' to find index.
    if ('A' <= str[i] && str[i] <= 'Z')
    index = str[i] – 'A';

    // If lowercase character,
    // subtract 'a' to find index.
    else if ('a' <= str[i]
    && str[i] <= 'z')
    index = str[i] – 'a';

    // If this character is not
    // an alphabet, skip to next one.
    else
    continue;

    mark[index] = true;
    }

    // Return false
    // if any character is unmarked
    for (int i = 0; i <= 25; i++)
    if (mark[i] == false)
    return (false);

    // If all characters were present
    return (true);
    }

    // Driver Code
    int main()
    {
    string str = "We promptly judged"
    " antique ivory"
    " buckles for the next prize";

    if (checkPangram(str) == true)
    printf("Yes");
    else
    printf("No");

    return (0);
    }


  • Pankaj

    str=” The quick brown fox jumps over the lazy dog”
    str=str.lower()
    fl=[]
    for i in str:
    if i.isalpha() and i not in fl:
    fl.append(i)
    if fl.__len__()==26:
    print(“String is pangram”)
    else:
    print(“string is not pangram”)


  • jasvinder

    #Python
    import string
    alpha = set(string.ascii_letters.lower())
    string = input()
    if set(string.lower()) >= alpha:
    print(“Yes, it is Pangram”)
    else:
    print(“Its not Pangram”)