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”


  • monu banerjee

    #include
    #include
    int main()
    {

    char str[]=”Abcd efgh ijklmn opqrst uvwxyz”;
    // gets(str);
    int count=97, res=0,j; //ascii value of a is 97
    strlwr(str); //lower case
    puts(str);
    int n=strlen(str);
    while(count!=123) //ascii value z is 122
    {

    for(j=0;j<n;j++)
    {
    if(str[j]==count)
    {
    res++;
    break;
    }
    }
    count++;
    }

    if(res==26)
    printf("Pangram");
    else
    printf("not pangram %d",res);

    }


  • Pradeepsurya

    # Python One-Liner

    “Not a pangram” if set(“abcdefghijklmnopqrstuvwxyz”) – set(input(“Please enter the string: “).lower()) else “Pangram”


  • Anmol

    static boolean pangram(String s){
    s=s.replaceAll(” “,””);
    s.toLowerCase();
    Set rs=new HashSet();
    for(int i=0;i<s.length();i++)
    {
    rs.add(s.charAt(i));
    if(set.size()==26)
    return true;
    }
    if(rs.size()==26)
    return true;
    return false;
    }


  • abhinay

    a=str(input(“enter”))
    b=a.lower()
    c=list(b.replace(” “,””))
    empty=[]
    alpha=list(‘abcdefghijklmnopqrstuvwxyz’)
    print(alpha)
    for i in c:
    if i in empty:
    pass
    elif (i.isalpha()!=True):
    pass
    else:
    empty.append(i)
    empty.sort()
    if (empty==alpha):
    print(“its a pangram”)
    else:
    print(“not a pangram”)


  • Yokesh Rana

    Java Solution for this problem
    package test;

    import java.util.Scanner;

    public class panagram {

    public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    String s=sc.nextLine();
    System.out.println(checkPanagram(s));

    }

    public static boolean checkPanagram(String s) {
    String temp=s.toUpperCase().replace(” “,””);
    //System.out.println(temp);
    boolean a[]=new boolean[26];
    for(int i=0;i<temp.length();i++) {
    a[temp.charAt(i)-65]=true;
    }
    for(int i=0;i<26;i++) {
    if(a[i]==false)
    return false;
    }
    return true;
    }
    }


  • Bakwas Insaan

    My O(n) solution
    import java.io.*;
    import java.util.*;
    class problem5{
    public static void main(String[] args){
    Scanner s=new Scanner(System.in);
    String str=s.nextLine();

    int[] a=new int[26];
    for(int i=0;i<str.length();i++){
    if(str.charAt(i)!=' ' && a[Character.toUpperCase(str.charAt(i))-'A']==0){
    a[Character.toUpperCase(str.charAt(i))-'A']++;
    }
    }
    for(int i=0;i<26;i++){
    if(a[i]==0){
    System.out.println(str+" is not a panagram");
    return;
    }

    }
    System.out.println(str+" is a panagram");

    }
    }


  • VAMSI CHOWDARY ATHIPATLA

    string=input(“”).lower()
    str=[]
    for i in string:
    if(i not in str and i!=” “):
    str.append(i)
    str.sort()
    if(str == [‘a’, ‘b’, ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘h’, ‘i’, ‘j’, ‘k’, ‘l’, ‘m’, ‘n’, ‘o’, ‘p’, ‘q’, ‘r’, ‘s’, ‘t’, ‘u’, ‘v’, ‘w’, ‘x’, ‘y’, ‘z’]):
    print(“PANGRAM”)
    else:
    print(“NOT A PANGRAM”)


  • Mohd Saif

    #python
    string=input()
    string=string.lower()
    string=set(string)
    alpha=[ch for ch in string if ord(ch) in range(ord(‘a’),ord(‘z’)+1)]
    if(len(alpha)==26):
    print(“pangram”)
    else:
    print(“not pangram”)


  • Vrinda Mittal

    public static void CheckPangram(String str) {
    char[] letters=str.toCharArray();
    HashMap hmap=new HashMap();
    for(int i=0;i<letters.length;i++) {
    if(letters[i]=’a’) {
    if(hmap.containsKey(letters[i])) {
    hmap.put(letters[i], hmap.get(letters[i])+1);
    } else {
    hmap.put(letters[i], 1);
    }
    }
    }
    if(hmap.size()==26) {
    System.out.println(str+” is a pangram”);
    } else {
    System.out.println(str+” is not a pangram”);
    }
    }


  • Koluboyina varaprasad

    import java.util.regex.Pattern;
    import java.util.regex.Matcher;
    import java.util.Scanner;
    import java.util.HashSet;
    public class tcsDigital {
    String s;
    tcsDigital()
    {
    Scanner scan=new Scanner(System.in);
    s=scan.nextLine();
    }
    public boolean isAlpha(char temp)
    {
    Pattern p=Pattern.compile(“[a-z]”);
    Matcher m=p.matcher(String.valueOf(temp));
    return m.matches();
    }
    public boolean check()
    {
    HashSet h=new HashSet();
    char []c=s.toCharArray();
    for(int i=0;i<c.length;i++)
    {
    if(isAlpha(c[i]))
    {
    h.add(c[i]);
    }
    }
    System.out.println(h.size());
    System.out.println(h);
    if(h.size()==26)
    return true;
    return false;
    }
    public static void main(String []args)
    {
    tcsDigital td=new tcsDigital();
    if(td.check())
    {
    System.out.println("Is A Pangram!");
    }
    else
    {
    System.out.println("Not A Pangram!");
    }
    }
    }


  • Pavan Kumar

    a=input()
    count=0
    b=’abcdefghijklmnopqrstuv’
    l=len(b)
    def pangram(ch):
    global count
    global a
    charset=a
    check=ch in charset
    if check==True:
    count+=1
    else:
    count=0
    return count

    for i in range(len(b)):
    c=pangram(b[i])

    if c==l:
    print(‘yes’)
    else:
    print(‘no’)