12345678910111213141516171819202122232425262728
#include <iostream> #include <sstream> using namespace std; bool isPalindrome(string s) { string tmp = s; int j = 0; for (int i = s.length()-1; i > 0; i--) { tmp[j] = s[i]; j++; } if (tmp == s) { return true; } return false; } int main() { string s; cout << "Enter a string: "; getline(cin, s); if (isPalindrome(s)) { cout << "It is a palindrome." << endl; } else { cout << "It is not a palindrome." << endl; } system("pause"); }
1234567891011121314
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { string a; getline(cin, a); if (a==reverse(a.begin(), a.end())) cout<<"It is a palindrome"<<endl; else cout<<"It's not a palindrome"<<endl; system("pause"); }