Question:

C++ program that will able to do palinchrome sentences?

by  |  earlier

0 LIKES UnLike

C++ program that will able to do palinchrome sentences?

 Tags:

   Report

1 ANSWERS


  1. Palindrome, perhaps? Here's a simple way to do it:

    #include <iostream>

    #include <string>

    using namespace std;

    bool isPalindrome(const string&);

    string strrev(const string&);

    int main(int argc, char *argv[]) {

      string s;

      cout << "> ";

      getline(cin,s);

      cout << s << " is ";

      if (isPalindrome(s) == false) cout << "not ";

      cout << "a palindrome" << endl;

      return 0;

    }

    bool isPalindrome(const string& s) {

      return (s == strrev(s));

    }

    string strrev(const string &s) {

      string r;

      

      for (string::const_reverse_iterator i = s.rbegin();

           i < s.rend(); ++i) {

        r.push_back(*i);

      }

      return r;

    }

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.