mercredi 5 octobre 2016

This pangram function in C++ doesn't satisfy all the test cases in HackerRank

Vote count: 0

I wanted to run a loop to check if every letter in the alphabet was present in the loop. If it was, I'd do an increment, and break the loop, so that it didn't read more than one time, in C++

    #include<iostream>
    using namespace std;
    class pangram                                          \\creating the class
    {
    string s;
    int count=0;                                           \\counter variable initialization
    public:
    void pan(void)                                         \\defining the method
        {
            cin>>s;                                         \\taking the string input
            for(char i='a';i<='z';i++)                       \\checking if every alphabet character is there in the string
                {
                    for(int j=0;j<s.length();j++)
                    {
                        char c=tolower(s[i]);                \\making them lowercase
                        if(i==c)
                        count++;
                        break;                               \\breaking the loop once that specific alphabet is found
                    }
                }
            if(count==26)
            cout<<"pangram";
            else
            cout<<"not pangram";
        }
    };
    pangram p1;
    int main()
    {
    p1.pan();                                            \\calling the object's method
    return 0;
    }

asked 19 secs ago

Let's block ads! (Why?)



This pangram function in C++ doesn't satisfy all the test cases in HackerRank

Aucun commentaire:

Enregistrer un commentaire