/************************************
Write a program that reads in two strings
from the user and tells the user whether
one is a reverse of the other.
************************************/
#include <iostream>
#include <string>
using namespace std;

bool reverses(string s1, string s2);

int main()
{
  // Get strings A and B
  string A, B;
  cout << "Enter string one: ";
  cin >> A;
  cout << "Enter string two: ";
  cin >> B;
  
  // Print whether A and B are reverses
  cout << "Strings are ";
  if (!reverses(A,B))
    cout << "not ";
  cout << "reverses of one another!" << 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;
}