Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. using namespace std;
  4.  
  5. char *clean(char *ph)
  6. {
  7. char *temp = new char[strlen(ph)];
  8. int ctr=0;
  9.  
  10. for (int i=0; i < strlen(ph); i++)
  11. {
  12. if (isalpha(ph[i]) || isdigit(ph[i]))
  13. temp[ctr++]= toupper(ph[i]);
  14. }
  15. return temp;
  16. }
  17.  
  18. char *reverse(char *orig)
  19. {
  20. orig = clean(orig);
  21.  
  22. int len =strlen(orig);
  23. char *temp = new char[len];
  24. int ctr=0;
  25.  
  26. for (int i=strlen(orig)-1; i >= 0; i--)
  27. temp[ctr++] = orig[i];
  28.  
  29. return temp;
  30. }
  31.  
  32. bool isPalindrome(char *ph)
  33. {
  34. return strcmp(clean(ph),reverse(ph)) == 0;
  35. }
  36.  
  37.  
  38. int main(int argc, char** argv) {
  39.  
  40. char phrase[100];
  41.  
  42. cout << "Please enter a word, or phrase :";
  43. gets(phrase);
  44.  
  45. cout << "\nBinali ana = " << reverse(phrase);
  46.  
  47. if (isPalindrome(phrase))
  48. cout << "\nIt's a palindrome";
  49. else
  50. cout << "\nIt is not a palindrome.";
  51.  
  52. return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement