nyoj_308_Substring_201405091611
Substring
- 描述
-
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 ;
}//最长公共子串
nyoj_308_Substring_201405091611的更多相关文章
随机推荐
- jsp中非空判断
function中uname要和id的值相匹配,但是这样不专业,要显示我的专业性,我将使用document获得name的值来判断是否为空,应为这样是专业的写法,我要时刻记住我是专业的 <scri ...
- ES6学习笔记(1)----let和const命令
参考书<ECMAScript 6入门>http://es6.ruanyifeng.com/ let和const命令 let 总结1.声明变量基本使用方法与var 相同 不同点 a.在代 ...
- [Tunny]Grunt基础介绍
[黄映焜/Tunny,20140711] Grunt是一个JavaScript任务管理器,对于需要反复重复的任务,例如压缩.编译.单元测试.代码检查等,自动化工具可以减轻你的劳动,简化你的工作. 本文 ...
- ALTER DOMAIN - 改变一个域的定义
SYNOPSIS ALTER DOMAIN name { SET DEFAULT expression | DROP DEFAULT } ALTER DOMAIN name { SET | DROP ...
- 转:函数调用的区别:_cdecl以及_stdcall
函数调用的几个概念:_stdcall,_cdecl.... 1._stdcall是Pascal程序的缺省调用方式,通常用于Win32 Api中,函数采用从右到左的压栈方式,自己在退出时清空堆栈.VC将 ...
- window10换系统为windows7
第一步 第二步 第三步 下载系统:http://www.dnxtc.net 1.GHO镜像安装器和WIN7,GHO文件必须一起放在除C盘外的其他盘的根目录 2.“GHO镜像安装器“工具上右键管理员方式 ...
- jdk11 eclipse下开启ZGC
平台支持 ZGC目前只在Linux/x64上可用,如果有足够的需求,将来可能会增加对其他平台的支持. 对的,目前只支持64位的linux系统. -_-' eclipse.ini配置: -XX:+Unl ...
- 浏览器通知js授权
// 获得权限 Notification.requestPermission(); // 点击按钮 document.querySelector('#button').addEventListener ...
- BZOJ 3876 支线剧情 有源汇有上下界最小费用可行流
题意: 给定一张拓扑图,每条边有边权,每次只能从第一个点出发沿着拓扑图走一条路径,求遍历所有边所需要的最小边权和 分析: 这道题乍一看,可能会想到什么最小链覆盖之类的,但是仔细一想,会发现不行,一是因 ...
- 笔试算法题(03):最小第K个数 & 判定BST后序序列
出题:输入N个整数,要求输出其中最小的K个数: 分析: 快速排序和最小堆都可以解决最小(大)K个数的问题(时间复杂度为O(NlogN)):另外可以建立大小为K的最大堆,将前K个数不断插入最大堆,对于之 ...