Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iomanip>
- using namespace std;
- int isPalindrome(char _a[])
- {
- int len = 0, flag = 0;
- while (_a[len] != '\0')
- {
- len++;
- }
- if (len % 2 == 0)
- {
- for (int i = 0, j = len - 1; i < len / 2; i++, j--)
- {
- if (_a[i] != _a[j])
- {
- flag = 1;
- break;
- }
- }
- }
- else
- {
- for (int i = 0, j = len - 1; i < (len - 1) / 2; i++, j--)
- {
- if (_a[i] != _a[j])
- {
- flag = 1;
- break;
- }
- }
- }
- if (len == 1)
- {
- return 1;
- }
- else if (flag == 1)
- {
- return 0;
- }
- else
- {
- return 1;
- }
- }
- int main()
- {
- int t;
- char a[20];
- cin >> t;
- while (t--)
- {
- cin >> a;
- if (isPalindrome(a) == 1)
- {
- cout << "YES" << endl;
- }
- else
- {
- cout << "NO" << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement