Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Gary Daniels and Evan Goldring - Mock whiteboard problem
Mar 29, 2007 at 12:18 AMHi All!
how about this
code does take in account for characters you want to skip,
but it does not check for case sensivivity
pure c++, not using any rtl
avoiding checking for special case if string is "ABA" for example
TCHAR ptszSkip[] = {' ', ',', '!', '-'};
bool IsPalindrome(TCHAR* ptsz)
{
bool bRet = false;
if(NULL != ptsz)
{
TCHAR* ptszEnd = ptsz;
while(*ptszEnd != 0) //get end pointer
{
++ptszEnd;
}
--ptszEnd;
bRet = true;
while(ptsz < ptszEnd)
{
bool bDoCheck = true;
for(size_t i = 0; i < sizeof(ptszSkip)/sizeof(ptszSkip[0]); i++)
{ /*check for skiped chars*/
if(*ptsz == ptszSkip[i])
{
++ptsz;
bDoCheck = false;
break;
}
if(*ptszEnd == ptszSkip[i])
{
--ptszEnd;
bDoCheck = false;
break;
}
}
if(bDoCheck)
{
if(*ptsz != *ptszEnd) //as soon as find first not equal chars , return false
{
bRet = false;
break;
}
++ptsz;
--ptszEnd;
}
}
}
return bRet;
}