Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- char *clean(char *ph)
- {
- char *temp = new char[strlen(ph)];
- int ctr=0;
- for (int i=0; i < strlen(ph); i++)
- {
- if (isalpha(ph[i]) || isdigit(ph[i]))
- temp[ctr++]= toupper(ph[i]);
- }
- return temp;
- }
- char *reverse(char *orig)
- {
- orig = clean(orig);
- int len =strlen(orig);
- char *temp = new char[len];
- int ctr=0;
- for (int i=strlen(orig)-1; i >= 0; i--)
- temp[ctr++] = orig[i];
- return temp;
- }
- bool isPalindrome(char *ph)
- {
- return strcmp(clean(ph),reverse(ph)) == 0;
- }
- int main(int argc, char** argv) {
- char phrase[100];
- cout << "Please enter a word, or phrase :";
- gets(phrase);
- cout << "\nBinali ana = " << reverse(phrase);
- if (isPalindrome(phrase))
- cout << "\nIt's a palindrome";
- else
- cout << "\nIt is not a palindrome.";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement