Guest User

Untitled

a guest
Dec 12th, 2019
79
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4. int isPalindrome(char _a[])
  5. {
  6. int len = 0, flag = 0;
  7. while (_a[len] != '\0')
  8. {
  9. len++;
  10. }
  11. if (len % 2 == 0)
  12. {
  13. for (int i = 0, j = len - 1; i < len / 2; i++, j--)
  14. {
  15. if (_a[i] != _a[j])
  16. {
  17. flag = 1;
  18. break;
  19. }
  20. }
  21. }
  22. else
  23. {
  24. for (int i = 0, j = len - 1; i < (len - 1) / 2; i++, j--)
  25. {
  26. if (_a[i] != _a[j])
  27. {
  28. flag = 1;
  29. break;
  30. }
  31. }
  32. }
  33. if (len == 1)
  34. {
  35. return 1;
  36. }
  37. else if (flag == 1)
  38. {
  39. return 0;
  40. }
  41. else
  42. {
  43. return 1;
  44. }
  45. }
  46.  
  47. int main()
  48. {
  49. int t;
  50. char a[20];
  51. cin >> t;
  52. while (t--)
  53. {
  54. cin >> a;
  55. if (isPalindrome(a) == 1)
  56. {
  57. cout << "YES" << endl;
  58. }
  59. else
  60. {
  61. cout << "NO" << endl;
  62. }
  63. }
  64. return 0;
  65. }
RAW Paste Data