/************************************
Write a program that reads in a string
from the user and tells the user whether
or not it is a palindrome.
************************************/
#include <iostream>
#include <string>
using namespace std;

bool reverses(string s1, string s2);

int main()
{
  // Get strings A and B
  string A;
  cout << "Enter string: ";
  cin >> A;
  
  // Print whether A and B are reverses
  cout << "String is ";
  if (!reverses(A,A))
    cout << "not ";
  cout << "a palindrome!" << endl;
  
  return 0;
}

// Tests whether s1 and s2 are reverses of one another
bool reverses(string s1, string s2)
{
  // Get lengths and make sure they're equal!
  int N1 = s1.size(), N2 = s2.size();
  if (N1 != N2)
    return false;
  
  // test forward on s1 and reverse on s2
  int F = 0, R = N1 - 1; 
  while(R >= 0)
  {
    if (s1[F] != s2[R])
      return false;
    F++;
    R--;
  }

  return true;
}