Ristha’s Pangrams

QUESTION

Ristha is 3 years old. She is very intelligent. She found a sentence \”The quick brown fox jumps over the lazy dog\” in her story book. She noticed that this sentence contains all the alphabets in English. \n\nShe told this to her mom. Mom told her that this sentence is a Pangram (Pangrams are sentences constructed by using every letter of the alphabet at least once.)\n\nShe got really interested in this. She started checking every sentences she go through. She got tired after a while..\nGiven a sentence s, help Ristha to check if it is a pangram or not.\n\nInput Format\n\nInput consists of a string s.\n\nConstraints \nLength of s can be at most 10^3(1<=|s|<=10^3) and it may contain spaces, lower case and upper case letters. Lower-case and upper-case instances of a letter are considered the same.\n\nOutput Format\n\nOutput a line containing pangram if s is a pangram, otherwise output not pangram.

ANSWER

#include<bits/stdc++.h>
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<bool> 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';
 
        // Mark current character
        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 Program to test above functions
int main()
{
 //   string str = "The quick brown fox jumps over the lazy dog";
// char str[50];
 // cin>>str;
 // cout<<str;
  string str;
  getline(std::cin,str);
    if(checkPangram(str)==true)
     //   printf (""%s is a pangram", str.c_str());
                cout<<"pangram";
    else
        //printf (""%s is not a pangram", str.c_str());
                cout<<"not pangram";
 
    return(0);
}
Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.

Powered By
100% Free SEO Tools - Tool Kits PRO