#CODEFORCESP7560. Palindromic Indices
Palindromic Indices
Palindromic Indices
题面翻译
题目描述
给定一个回文字符串 ,它的长度为 ,问一共有多少种方式使它去掉一个字符后仍是回文字符串。
输入格式
共有 组数据,对于每组数据,先输入字符串的长度 ,再输入回文字符串 。
输出格式
对于每组数据,输出一共有多少种方式使输入的字符串去掉一个字符后仍是回文字符串。
数据范围
数据保证所有的 之和不超过 。
题目描述
You are given a palindromic string of length .
You have to count the number of indices such that the string after removing from still remains a palindrome.
For example, consider = "aba"
- If we remove from , the string becomes "ba" which is not a palindrome.
- If we remove from , the string becomes "aa" which is a palindrome.
- If we remove from , the string becomes "ab" which is not a palindrome.
A palindrome is a string that reads the same backward as forward. For example, "abba", "a", "fef" are palindromes whereas "codeforces", "acd", "xy" are not.
输入格式
The input consists of multiple test cases. The first line of the input contains a single integer — the number of test cases. Description of the test cases follows.
The first line of each testcase contains a single integer — the length of string .
The second line of each test case contains a string consisting of lowercase English letters. It is guaranteed that is a palindrome.
It is guaranteed that sum of over all test cases does not exceed .
输出格式
For each test case, output a single integer — the number of indices such that the string after removing from still remains a palindrome.
样例 #1
样例输入 #1
3
3
aba
8
acaaaaca
2
dd
样例输出 #1
1
4
2
提示
The first test case is described in the statement.
In the second test case, the indices that result in palindrome after removing are . Hence the answer is .
In the third test case, removal of any of the indices results in "d" which is a palindrome. Hence the answer is .