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

nyoj_308_Substring_201405091611的更多相关文章

随机推荐

  1. [BZOJ1798][AHOI2009]Seq维护序列 线段树

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1798 一眼看过去线段树,事实上就是线段树.对于乘和加的两个标记,我们可以规定一个顺序,比如 ...

  2. fullpagejs实现的拥有header和foooter的全屏滚动demo/fullpage footer

    fullpagejs实现的拥有header和foooter的全屏滚动, 技术要点:给section元素加fp-auto-height类, <!DOCTYPE html> <html ...

  3. ListView相关知识点

    最近开发接触到了ListView控件,其实简单的需求基本上源生的都可以满足,下面总结一下开发过程中所遇到的关键点: 1.多级ListView联动,保存位置:即切换第一层ListView的item过程中 ...

  4. iOS-UI控件之UIImageView

    contentMode属性 带有scale单词的:图片有可能会拉伸 UIViewContentModeScaleToFill 将图片拉伸至填充整个imageView 图片显示的尺寸跟imageView ...

  5. asp.net 实现treeview 选中父节点其子节点也选种中 选中子节点其父节点与根节点也被选中

    1.在 Page_Load(object sender, EventArgs e) 里面加入: TreeView1.Attributes.Add("onclick", " ...

  6. CSS中的趣事之float浮动

       浮动float一般跟left或是right: 特性: 1,包裹性:浮动文本类型时,需要指定宽度width,如果不指定,就会折叠到最小宽度: 2,浮动会影响别的元素: 3,子级浮动,会导致父级高度 ...

  7. Node.js+Express+MVC+Mysql小白创建新项目

    1.打开CMD命令窗口,这一步不会的,回家休息,不要看了 2.npm install -g yo  等待时间看个人电脑情况. 如果没有npm命令,建议先安装npm ,npm安装介绍:https://d ...

  8. java_udp编程

    两个重要的类: https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/net/DatagramPacket.html ht ...

  9. 并发-5CAS与AQS

    juc: java.util.concurrent 锁: 悲观锁:写的比较多,对数据的增删改,读(查)少.Lock 乐观锁:反之,读多写少.版本 并发编程之 CAS 的原理 什么是CAS CAS (c ...

  10. 借助百度地图API制作企业百度地图

    做网站需要插入地图,可以借助百度地图API,具体步骤如下: 1.打开百度地图API的网址:   http://api.map.baidu.com/lbsapi/creatmap/ 2.设置中心点 3. ...