欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1027A.Palindromic Twist
Palindromic Twist
You are given a string consisting of lowercase Latin letters. is even.
For each position () in string you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.
For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.
That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' 'd', 'o' 'p', 'd' 'e', 'e' 'd', 'f' 'e', 'o' 'p', 'r' 'q', 'c' 'b', 'e' 'f', 's' 't').
String is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.
Your goal is to check if it's possible to make string a palindrome by applying the aforementioned changes to every position. Print "YES" if string can be transformed to a palindrome and "NO" otherwise.
Each testcase contains several strings, for each of them you are required to solve the problem separately.
Input
The first line contains a single integer () — the number of strings in a testcase.
Then lines follow — lines and of them describe the -th string. The first line of the pair contains a single integer (, is even) — the length of the corresponding string. The second line of the pair contains a string , consisting of lowercase Latin letters.
Output
Print lines. The -th line should contain the answer to the -th string of the input. Print "YES" if it's possible to make the -th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise.
Note
The first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.
The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.
The third string can be changed to "beeb" which is a palindrome.
The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm".
Samples
5
6
abccba
2
cf
4
adfa
8
abaazaba
2
ml
YES
NO
YES
NO
NO
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |