codeforces 1027 A. Palindromic Twist

题目描述:http://codeforces.com/contest/1027/problem/A

c++ 代码:(这个题做麻烦了,自己的提升空间很大,路还很长)

#include 
#include 

using namespace std;



bool judge(char a,char b)
{
    char c[2],d[2];
     c[0]=a-1>='a'?a-1:0;
     c[1]=a+1<='z'?a+1:0;
     d[0]=b-1>='a'?b-1:0;
     d[1]=b+1<='z'?b+1:0;
     int cnt=0;
    while(cnt<2) {
       for(int i=0;i<2;i++) {
        //cout << c[cnt] << " " <
        if(c[cnt]&&d[i]&&c[cnt]==d[i]){return true;}
        }
     cnt++;
    }

    return false;
}


int main() {
   int t;
   cin >> t;
   while(t--) {
      int n;
      string s;
      cin >> n;
      cin >> s;
      bool flag=0;
      for(int i=0;i2;i++) {
          if(judge(s[i],s[n-i-1]));
          else flag=1;
      }
      /*
      else {
        if(s[0]==s[1]);
        else flag=1;
      }*/
      if(flag)cout << "NO" <else cout << "YES" <return 0;
}

你可能感兴趣的:(codeforces)