Advertisement
fahimkamal63

Save Ironman

Apr 22nd, 2019
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<cctype>
  4.  
  5. using namespace std;
  6.  
  7. int take_alphabet(string &s, int n){
  8.     int i;
  9.     for(i = 0; i < n; i++){
  10.         s[i] = tolower(s[i]);
  11.         if(s[i] >= 'a' && s[i] <= 'z'){
  12.             continue;
  13.         }
  14.         else{
  15.             s.erase(i,1);
  16.             i--; n--;
  17.         }
  18.     }
  19.     return n;
  20. }
  21.  
  22. void reverse_str(string &s, int n){
  23.     int i = 0, j = n-1;
  24.     while(i < j){
  25.         s[i] = tolower(s[i]);
  26.         s[j] = tolower(s[j]);
  27.         char temp = s[i];
  28.         s[i] = s[j];
  29.         s[j] = temp;
  30.         i++; j--;
  31.     }
  32. }
  33.  
  34. int main(){
  35.     int t; cin >> t;
  36.     while(t--){
  37.         string str;
  38.         cin.ignore();
  39.         getline(cin , str);
  40.         int n = str.length();
  41.         n = take_alphabet(str, n);
  42.         //cout << str << endl;
  43.         string rev = str;
  44.         n = rev.length();
  45.         reverse_str(rev, n);
  46.         //cout << rev << endl;
  47.         int flag = 0;
  48.         for(int i = 0; i < n; i++){
  49.             if((str[i] >= 'a' && str[i] <= 'z') &&(rev[i] >= 'a' && rev[i] <= 'z')){
  50.                 if(str[i] != rev[i]){
  51.                     flag = 1;
  52.                     break;
  53.                 }
  54.             }
  55.         }
  56.         if(flag) cout << "NO\n";
  57.         else cout << "YES\n";
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement