Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by fillip ( 2 years ago )
//PALINDROME
#include <iostream>
#include <string>
#include <stack>
using namespace std;
bool isPalindrome(const string& str) {
stack<char> s;
int length=str.length();
int half_length=length/2;
for (int i=0; i<half_length; ++i) {
s.push(str[i]);
}
int start_index=half_length+(length % 2);
for (int i=start_index; i<length; ++i) {
if (str[i]!=s.top()) {
return false;
}
s.pop();
}
return true;
}
int main() {
string str;
cout<<"Enter a string to check if it is a palindrome: ";
cin>>str;
if (isPalindrome(str)) {
cout<<str<<" is a palindrome."<< endl;
} else {
cout<<str<<" is not a palindrome."<< endl;
}
return 0;
}
Revise this Paste
Parent: 127153