SRM 564, D2, 250-Pointer (FauxPalindromes)

James S. Plank

Fri Dec 21 14:24:29 EST 2018

In case Topcoder's servers are down

Here is a summary of the problem:

The examples

Example Input Answer
0
"ANA"
"PALINDROME"
1
"AAAAANNAA"
"FAUX"
2
"LEGENDARY"
"NOT EVEN FAUX"
3
"XXXYTYYTTYX"
"FAUX"
4
"TOPCOODEREDOOCPOT"
"PALINDROME"
5
"TOPCODEREDOOCPOT"
"FAUX"
6
"XXXXYYYYYZZXXYYY"
"NOT EVEN FAUX"


Testing yourself

Like the Cryptography Problem, I have a shell script tests.sh , that you can use to test your program. When you run tests.sh, your answer should be identical to answers.txt.

Hints

Give this one a try, and if you want help, then scroll down and read below.







































You have three cases to determine:
  1. Palindrome?
  2. Not Palindrome, but Faux?
  3. Not even Faux?
It's best to tackle these in order. My strategy here was to write a procedure (or method) called ispal(string s), which returned 1 if the string was a palendrome, and 0 otherwise. I then called it on word, and returned "PALINDROME" if it was a palindrome, and "NOT" otherwise. I tested this on examples 0 through 6.

Next, I constructed a new string s, which was equal to word with no consecutive identical characters. After testing this, I called ispal() on it, and that let me return either "FAUX" or "NOT EVEN FAUX".

Done.