codeforces-1027 A Palindromic Twist
1 #include <iostream> 2 #include <unordered_map> 3 #include <algorithm> 4 #include <vector> 5 #include <queue> 6 7 using namespace std; 8 9 bool sppalindjudge(string s,int n) 10 { 11 char* pre = &s[0]; 12 char* end = &s[n-1]; 13 while(pre < end) 14 { 15 if(abs((*pre)-(*end))==0 || abs((*pre)-(*end))==2) 16 { 17 pre ++; 18 end --; 19 } 20 else 21 { 22 return false; 23 } 24 } 25 return true; 26 } 27 28 int main() 29 { 30 int T; 31 while(cin >> T) 32 { 33 while(T --) 34 { 35 int n; 36 string s; 37 cin >> n; 38 cin >> s; 39 bool result = sppalindjudge(s,n); 40 if(result) 41 cout << "YES" << endl; 42 else 43 cout << "NO" << endl; 44 } 45 } 46 return 0; 47 }