import java.io.*;

public class Palin {

  public static void main (String[] args) throws IOException {

    InputStreamReader in = new InputStreamReader (System.in);
    BufferedReader keyboard = new BufferedReader (in);

    while (true) {

      System.out.println ("Type a word or phrase.");
      System.out.println ("I will check and see if it is a palindrome.");

      String s = keyboard.readLine ();
      System.out.println ("You typed: " + s);

      if (s.equals ("stop")) {
	System.out.println ("I guess that means I'll stop now.");
	System.out.println ("By the way, stop is not a palindrome.");
	return;
      }

      if (isItPalindrome (s)) {
	System.out.println (s + " is a palindrome!");
      } else {
	System.out.println (s + " is not a palindrome.");
      }
    }
  }

  // middle returns a substring that includes all but the
  // first and last; only works if s has at least two characters
  public static String middle (String s) {
    int length = s.length();
    return s.substring (1, length-1);
  }

  // first returns the first character of a string
  // first only works if s has at least one characters
  public static char first (String s) {
    return s.charAt (0);
  }

  // last returns the last character of a string
  // last only works if s has at least one characters
  public static char last (String s) {
    int len = s.length();
    return s.charAt (len - 1);
  }

  // tail returns all but the last two characters of the
  // String.  it is completely bulletproof; there are no
  // preconditions.  
  public static String tail (String s) {
    if (s == null) return "";
    int len = s.length();
    if (len == 0 || len == 1) {
      return "";
    }
    return s.substring (2, len);
  }

  // second returns the second character of a string
  // it only works if there are at least two characters

  public static char second (String s) {
    return s.charAt (1);
  }

  public static boolean isPalindrome (String s) {
    int len = s.length();
    if (len == 0 || len == 1) {
      return true;
    }

    // at this point we know that len>=2, so it is safe
    // to invoke first, last, and middle

    if (first(s) != last(s)) {
      return false;
    } else {
      boolean recurse = isPalindrome (middle (s));
      return recurse;
    }
  }

  // here is the iterative version of Palindrome

  public static boolean isItPalindrome (String s) {
    int len = s.length();

    int i = 0;
    int j = len-1;

    while (i < j) {
      if (s.charAt(i) != s.charAt(j)) {
	return false;
      }
      i++;
      j--;
    }

    // if we get all the way through the loop and
    // never found a mismatched pair, it must be true!
    return true;
  }

  public static boolean isDupledrome (String s) {
    if (s == null) return false;
    int len = s.length();

    // the empty string is a dupledrome
    if (len == 0) return true;

    // any string with an odd number of letters is not.
    if (len%2 == 1) return false;

    // at this point, is it safe to invoke second?

    if (first(s) == second(s)) {
      return isDupledrome (tail (s));
    } else {
      return false;
    }
  }

  public static boolean isItDupledrome (String s) {
    if (s == null) return false;
    int len = s.length();

    int i = 0;

    while (i < len-1) {
      if (s.charAt(i) != s.charAt(i+1)) {
	return false;
      }
      i = i + 1;
    }
    return true;
  }

  public static boolean hasComma (String s) {
    int index = s.indexOf(',');
    return (index != -1);
  }

  public static String convertName (String s) {
    if (hasComma (s)) {
      return s;
    }
    int space = s.indexOf(' ');
    int len = s.length();
    String first = s.substring (0, space);
    String last = s.substring (space+1, len);
    return last + ", " + first;
  }
}
