01: #include <iostream>
02: #include <string>
03: #include <vector>
05: using namespace std;
07: /**
08:    Tests whether a string is a palindrome. A palindrome
09:    is equal to its reverse, for example "rotor" or "racecar".
10:    @param s a string
11:    @return true if s is a palindrome
12: */
13: bool is_palindrome(string s)
14: {  // separate case for shortest strings
16:    if (s.length() <= 1) return true;
17: 
18:    // get first and last character, converted to lowercase   
19:    char first = s[0];
20:    char last = s[s.length() - 1];
21: 
22:    if (first == last)
23:    {  string shorter = s.substr(1, s.length() - 2);
25:       return is_palindrome(shorter);
26:    }
27:    else return false;
29: }
30: 
31: int main()
32: {  cout << "Enter a string: ";
34:    string input;
35:    getline(cin, input);
36:    cout << input << " is ";
37:    if (!is_palindrome(input)) cout << "not ";
38:    cout << "a palindrome" << endl;
39:    return 0;
40: }