Saturday, 18 June 2016

A C++ Program to check if the given string is a pangram or not Problem Solution.

Pangram Checking

A pangram is a sentence containing every letter in the English Alphabet.

Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
bool checkPangram (string str){
 
    vector<bool> check(26, false);
    int index,len = str.length();
    for (int i = 0; i < len; i++){
        if (str[i] >= 'A' && str[i] <= 'Z')index = str[i] - 'A';
        else if(str[i] >= 'a' && str[i] <= 'z')index = str[i] - 'a';
        check[index] = true;
    }
    for (int i = 0; i <= 25; i++)
        if (!check[i])return false;
    return true;
}

int main(){
 
    string str = "The quick brown fox jumps over the lazy dog";
    
    if (checkPangram(str))cout << "\"" << str << "\"" << " is a pangram." << endl;
    else cout << "\"" << str << "\"" << " is not a pangram." << endl;
 
    return 0;
}

Output:


No comments:

Post a Comment