Note: this is a harder version of Mirrored string I.

The gorillas have recently discovered that the image on the surface of the water is actually a reflection of themselves. So, the next thing for them to discover is mirrored strings.

A mirrored string is a palindrome string that will not change if you view it on a mirror.

Examples of mirrored strings are "MOM", "IOI" or "HUH". Therefore, mirrored strings must contain only mirrored letters {A, H, I, M, O, T, U, V, W, X, Y} and be a palindrome.

e.g. IWWI, MHHM are mirrored strings, while IWIW, TFC are not.

A palindrome is a string that is read the same forwards and backwards.

Given a string S of length N, help the gorillas by printing the length of the longest mirrored substring that can be made from string S.

A substring is a (possibly empty) string of characters that is contained in another string S. e.g. "Hell" is a substring of "Hello".

Input

The first line of input is T – the number of test cases.

Each test case contains a non-empty string S of maximum length 1000. The string contains only uppercase English letters.

Output

For each test case, output on a line a single integer - the length of the longest mirrored substring that can be made from string S.

Example
Input

Copy
3
IOIKIOOI
ROQ
WOWMAN
Output

Copy
4
1
3
题解:暴力呀。
 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
#define PI acos(-1.0)
using namespace std;
bool judge(char arr)
{
if(arr=='A'||arr=='H'||arr=='I'||arr=='M'||arr=='O'||arr=='T'||arr=='U'||arr=='V'||arr=='W'||arr=='X'||arr=='Y')
return false;
return true;
}
int main()
{
int i,j,n,k,m,kk;
char str[];
scanf("%d",&n);
while(n--)
{
int ans=,pp;
scanf(" %s",&str);
for(i=;i<strlen(str);i++)
for(j=i;j<strlen(str);j++)
{
if(judge(str[j]))
break;
if(str[j]==str[i])
{
m=j;int sum=;
for(k=i;k<(i+j+)/;k++)
{
if(str[k]==str[m--])
sum++;
}
if(sum==(j-i+)/)
ans=max(ans,j-i+);
} }
printf("%d\n",ans); }
return ;
}

最新文章

  1. JS控制div跳转到指定的位置的解决方案总结
  2. 出现个Expression(str != NULL)
  3. Qt窗口的屏幕居中显示
  4. Codeforces Round #242 (Div. 2) B. Megacity
  5. Service(一)-----&gt;简单计算
  6. C#操作office进行Excel图表创建,保存本地,word获取
  7. Swift学习笔记七
  8. http://nxlhero.blog.51cto.com/962631/1666250?plg_nld=1&amp;plg_uin=1&amp;plg_auth=1&amp;plg_nld=1&amp;plg_usr=1&amp;plg_vkey=1&amp;plg_dev=1
  9. 关于Arrays类总结
  10. Java吸收换行符
  11. GitHub 的分支创建与合并
  12. shell基础(转)
  13. List分组 用于客服对话分组场景
  14. Winform界面中实现菜单列表的动态个性化配置管理
  15. Python列表操作
  16. linux服务器ssh免密登录
  17. Linux网络那点事(CentOS、Ubuntu、Kali)
  18. PAT A1136 A Delayed Palindrome (20 分)——回文,大整数
  19. day22 ramdom 模块
  20. 学习stm32 让我们一起回顾一下C语言吧

热门文章

  1. LeetCode OJ:Roman to Integer(转换罗马字符到整数)
  2. 面试题总结(三)、《STL源码剖析》相关面试题总结
  3. Arcgis for Javascript之统计图的实现
  4. python之Beautiful Soup库
  5. Jar包进行反编译,修改后重新打包
  6. sql_自连接,181,182,196,197
  7. vue前端开发那些事——vue组件开发
  8. vuecli3 运行报错
  9. mysql之 explain、optimizer_trace 执行计划
  10. 第12篇 PSR-1规范