// Exercise 4
//
// Write a function to test if a string is
// a palidrome

#include <iostream>
#include <string>

// Function to test if string is a palidrome
// This is not optimal as you should never need to test
// more than half of the input string
int palindromic(std::string str) {
  int last = str.length() - 1;
  for (int i = 0; i < last; i++) {
    // Use the "at" method of strings to aqcuire the character
    if (str.at(i) != str.at(last-i)) {
      // Found a non-matching character
      return 0;
    }
  }
  // All characters examined matched
  return 1;
}

// Test program

int main(int argc, char **argv)
{
  std::string x;
  std::cout << "Enter a string: ";
  std::cin >> x;
  std::cout << x << " is ";
  if (! palindromic(x)) {
    std::cout << "not ";
  }
  std::cout << "a palidrome.\n";
}
