HackerRank 'Pangrams' Solution

by Srikant Padala on May 24, 2016, 12:22 pm


Explanation


  • Convert to lower case letters
  • All the characters should be present atleast once

Pangrams Problem Statement

Video

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

string isPangram(string &sentence) {
    transform(sentence.begin(), sentence.end(), sentence.begin(), ::tolower);
    bool c[26];
    for(int i=0; i < sentence.size(); i++) {
        if(isalpha(sentence[i])) {
            c[sentence[i] - 'a'] = true;
        }
    }
    for(int i=0; i < 26; i++) {
        if(!c[i]) return "not pangram";
    }
    return "pangram";
}

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 
    string sentence;
    getline(cin, sentence);
    cout << isPangram(sentence);
    return 0;
}

Coming Soon.