I have a piece of psuedocade here and it is supposed to check if a sentence entered by a user is a pangram or not. Please have a look at it.
string sentence;
bool pangram ßtrue;
ARRAY: characterArray of [26] char ß {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
ARRAY: sCharacterArray of char ß { '.', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '-', '=', '<', '|', '/', '>' };
Input the sentence
for (int i ß0;i <characterArray.Length; i++)
IF (!sentence.ToLower().Contains(characterArray[i]))
pangram ß false
ELSE
{
for(int x = 0; x < sCharArray.Length; x++)
{
if(sentence.Contains(sCharArray[x]))
{
pangram=false;
}
else
{
pangram=true;
}
}
}
ENDIF
ENDFOR
if ( pangram ßtrue)
Display ('pangram');
else
Display ('not a pangram');
ENDIF
//end program
Feedback will be appreciated. Thank you.
Hiren JoshiPosted Oct 14, 2011, 12:13 PM
VulpesPosted Oct 14, 2011, 7:10 AM
Doubtless there will be even faster methods than this.
Hiren JoshiPosted Oct 14, 2011, 12:34 AM
Hiren JoshiPosted Oct 14, 2011, 12:33 AM
VulpesPosted Apr 18, 2011, 5:52 AM
The only situation where the pseudocode as it stands would be superior is if the sentence didn't contain 'a', in which case the code would never check for excluded characters. However, in a sentence of any length this is unlikely as 'a' is of course a common letter.
If it does contain an 'a' then the code will check for excluded characters at least once and probably multiple times in a sentence of any length.
RoyaltyPosted Apr 18, 2011, 5:46 AM
VulpesPosted Apr 18, 2011, 5:33 AM
This is because it is checking multiple times for 'excluded' characters. It would be better just to check once to see if the sentence includes any excluded characters and, if it does, then it's definitely not a pangram.
Otherwise, you can then check to see whether the sentence contains all 26 letters of the alphabet at least once.