0

Hi all. I am trying to create a function to check if a string is a pangram or not. I think I have good start on it, but I can't figure out how to check if the characters in the string are unique. I have to do this recursively with no global or static variables. I created a counter variable the gets incremented every time the isPangram function gets called. I figure since there are 26 letters in the alphabet, if I can figure out how to insert 26 unique characters into a new string from the old string that would make it a pangram. Here is my code so far. Any pointers would be grateful.

#include <iostream>
#include <string>
using namespace std;

bool isPangram(string str, int counter, int last_index)
{
    if(counter >= 26)
    {
		return true;
	}
	else
	{
	    return isPangram(str, ++counter, --last_index);
	    //return false;
	}
}
bool isPangram(string str)
{
   return isPangram(str, 0, str.length() - 1);
}
2
Contributors
2
Replies
6
Views
7 Years
Discussion Span
Last Post by iCode@Night
0

You could have 26 integers variables each assigned to a letter or a boolean array, whenever you parse one of the letters you change the appropriate integer to 1 and have a checking function to make sure that if any of the integers is above 1 you reject it and if your looping switch them all to 0 at the end.

0

I cannot use any global or static variables and it has to be done recursively.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.