borisshr
BAN USEROne more
#include <iostream>
#include <string>
using namespace std;
inline bool IsValid(char c)
{
return (c >= 'a' && c <= 'z') //lowercase alpha
|| (c >= 'A' && c <= 'Z') //Uppercase alpha
|| (c >= '0' && c <= '9'); //Numerics
}
inline char ToLower(char c)
{
if ( c >= 'A' && c <= 'Z')
return c - 'A' + 'a';
return c;
}
bool IsPalindrome( string str)
{
string::iterator i = str.begin();
string::iterator j = str.end() - 1;
while ( i < j ) {
if ( !IsValid(*i) ) { ++i; continue; }
if ( !IsValid(*j) ) { --j; continue; }
if ( ToLower( *i) != ToLower( *j))
return false;
++i;--j;
}
return true;
}
C++ version
#include <iostream>
#include <string>
using namespace std;
inline bool IsValid(char c)
{
return (c >= 'a' && c <= 'z') //lowercase alpha
|| (c >= 'A' && c <= 'Z') //Uppercase alpha
|| (c >= '0' && c <= '9'); //Numerics
}
inline char ToLower(char c)
{
if ( c >= 'A' && c <= 'Z')
return c - 'A' + 'a';
return c;
}
bool IsPalindrome( string str)
{
string::iterator i = str.begin();
string::iterator j = str.end() - 1;
string::iterator beg = str.begin();
string::iterator end = str.end();
do {
while( i != end && !IsValid(*i) ) ++i; // get valid char from current i position
while( !IsValid(*j) ) { --j; if (j == beg) break; } // get valid char from current j position
if ( i > j)
break;
if ( ToLower( *i) != ToLower( *j))
return false;
++i; --j;
} while(1);
return true;
}
The bit matrix with letters naming the columns and rows can be representing the relations between letters. For example the relation L->N can be represented by one in position {L, N}.
Using this matrix we can just sort the letters to get the character sequence in this new language
Non-recursive version. C++
Idea is that on every digit you can
1. Treat it as a standalone digit
2. Complete 2-digit combo started on previous digit
3. Start new 2-digit combo
cases 1 and 2 add up to complete_mappings
case 3 carries previous value of complete_mappings over to next iteration as incomplete_mappings
- borisshr August 10, 2015