Substring

时间限制:1000 ms  |           内存限制:65535 KB
难度:1
 
描述

You are given a string input. You are to find the longest substring of input such that the reversal of the substring is also a substring of input. In case of a tie, return the string that occurs earliest in input.

Note well: The substring and its reversal may overlap partially or completely. The entire original string is itself a valid substring . The best we can do is find a one character substring, so we implement the tie-breaker rule of taking the earliest one first.

 
输入
The first line of input gives a single integer, 1 ≤ N ≤ 10,  the number of test cases. Then follow, for each test case,  a  line  containing between 1 and 50 characters, inclusive. Each character of input will be an uppercase letter ('A'-'Z').
输出
Output for each test case  the longest substring of input such that the reversal of the substring is also a substring of input
样例输入
3
ABCABA
XYZ
XCVCX
样例输出
ABA
X
XCVCX
来源
第四届河南省程序设计大赛
上传者
张云聪
 #include <stdio.h>
#include <string.h>
int map[][];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int i,j,len,max=,t;
char str1[],str2[];
memset(map,,sizeof(map));
scanf("%s",str1);
len = strlen(str1);
for(i=;i<len;i++)
str2[i]=str1[len--i];
for(i=;i<len;i++)
{
for(j=;j<len;j++)
{
if(str1[i]==str2[j])
map[i+][j+] = map[i][j]+;
if(map[i+][j+]>max)
{
max = map[i+][j+];
t = i+;
}
}
}
for(i=t-max;i<t;i++)
printf("%c",str1[i]);
printf("\n");
}
return ;
}

//最长公共子串

//http://i.cnblogs.com/EditPosts.aspx?postid=3582994

最新文章

  1. JSP网站开发基础总结《二》
  2. android DevicePolicyManager实现一键锁屏
  3. 单片机TM4C123学习(七):I2C模块(温度传感器)
  4. 使用JavaMail API发送邮件
  5. .net 科学类型相关问题
  6. 初谈SQL Server逻辑读、物理读、预读【转】
  7. xslt中的常用函数
  8. Linux了解进程的地址空间
  9. 设计模式NO.1
  10. 新手必备的Linux知识
  11. 【apache2】AH00543: httpd: bad user name apache
  12. 购物车的实现(jsp的session+Java的Map的结合)
  13. C#编程(二十七)----------创建泛型类
  14. NFS 挂载 + autofs
  15. nginx学习笔记(8)虚拟主机名---转载
  16. 23 DesignPatterns学习笔记:C++语言实现 --- 1.3 Singletion
  17. 使用 Go 的 struct tag 来解析版本号字符串
  18. centos运行asp.netcore的正确姿势
  19. 【题解】Atcoder ARC#94 F-Normalization
  20. 小白如何将代码上传到github上?

热门文章

  1. Android开发学习——android反编译
  2. outlook 通讯录分类--2017年1月16日--对联系人分类管理
  3. DELL笔记本安装Ubuntu 14.04
  4. Scala基础篇-01变量,数据类型
  5. 5 Transforms 转移 笔记
  6. Node.js——重定向
  7. Oracle使用plsql连不上本地数据库,cmd中使用sqlplus连的上的可能解决方案
  8. 【东软实训】SQLselect及其相关操作
  9. [Python3网络爬虫开发实战] 1.2.1-Requests的安装
  10. 零基础入门学习Python(15)--格式化