codeforces Pangram in c++

Here is an example of a C++ program to check if a given string is a pangram:

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

bool isPangram(string str) {
    transform(str.begin(), str.end(), str.begin(), ::tolower);

    bool alphabets[26] = {false};

    for (char c : str) {
        if (c >= 'a' && c <= 'z') {
            alphabets[c - 'a'] = true;
        }
    }

    for (bool b : alphabets) {
        if (!b) {
            return false;
        }
    }

    return true;
}

int main() {
    string str;
    cout << "Enter a string: ";
    getline(cin, str);

    if (isPangram(str)) {
        cout << "The string is a pangram." << endl;
    } else {
        cout << "The string is not a pangram." << endl;
    }

    return 0;
}

Explanation:

  1. The isPangram function takes a string as input and returns a boolean value indicating whether the string is a pangram or not. A pangram is a sentence that contains every letter of the alphabet at least once.

  2. The transform function is used to convert all characters in the string to lowercase. This is done to handle both uppercase and lowercase letters in the input string.

  3. The alphabets array is a boolean array of size 26, initialized with false values. Each index in the array represents a letter of the alphabet, starting from 'a' at index 0 to 'z' at index 25.

  4. The loop iterates over each character in the input string. If the character is a lowercase letter, its corresponding index in the alphabets array is set to true.

  5. After iterating through all the characters, another loop checks if any of the elements in the alphabets array is still false. If any element is false, it means that the corresponding letter is missing in the input string, and the function returns false.

  6. If all elements in the alphabets array are true, it means that all letters of the alphabet are present in the input string, and the function returns true.

  7. In the main function, the user is prompted to enter a string. The getline function is used to read the entire line, including spaces.

  8. The isPangram function is called with the user's input string as an argument. If it returns true, the program displays the message "The string is a pangram." If it returns false, the program displays the message "The string is not a pangram."

  9. Finally, the program returns 0 to indicate successful execution.