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. C#_JDBC连接数据库

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. window.form增删改查

    效果展示: 查询: 可以查询姓名:民族:姓名+民族:都是空的查询全部 取值取得是姓名: 删除: 修改: 先选中查询之后修改: 添加: 代码部分: 第一张表: 第二张表:主表,民族代码加名称 natio ...

  3. T4869 某种数列问题 (jx.cpp/c/pas) 1000MS 256MB

    题目描述 众所周知,chenzeyu97有无数的妹子(阿掉!>_<),而且他还有很多恶趣味的问题,继上次纠结于一排妹子的排法以后,今天他有非(chi)常(bao)认(cheng)真(zhe ...

  4. kubernetesV1.13.1一键部署脚本(k8s自动部署脚本)

    部署k8sv1.13.1只需要下面几步就OK了: git clone https://github.com/luckman666/deploy_Kubernetes-v1.13.1.git cd de ...

  5. 04全志R58平台编译内核需要选择的配置

    04全志R58平台编译内核需要选择的配置 2018/11/6 14:19 版本:V1.0 开发板:SC5806 1.系统编译:(略) 每次系统编译/内核的时候都需要选3次N: * * Xtables ...

  6. Java编程思想总结笔记Chapter 3

    本章需要总结的不多,但细节的东西需要注意,有些很容易遗忘. 第三章 目录: 3.1 更简单的打印语句 3.2 使用Java操作符 3.3 优先级 3.4 赋值 3.5 算数操作符 3.6 自动递增和递 ...

  7. leetcode:single-number-ii(Java位运算)

    题目 Given an array of integers, every element appears three times except for one. Find that single on ...

  8. Can't find bundle for base name messages.AndroidJpsBundle, locale zh_CN

     从http://www.android-studio.org/网站上下载了一个Android Studio 3.0的非安装版本(android-studio-ide-171.4408382-wind ...

  9. Linux关于文件的权限笔记

    1.调整文件的权限命令:chmodLinux的每个文件都定义了文件的拥有者:u(user).拥有组:g(group).其他人:o(others)权限,对应的权限用rwx的组合来定义.使用chmod命令 ...

  10. python 需求分析

    第三章: 需求分析需求分析任务: ??? 功能分析性能分析EG: 相应时间.主存容量.磁盘容量.安全性.等可靠性和可用性出错处理需求系统发现错误时采取的行动,主要在系统关键部分设置接口需求用户接口.硬 ...