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的更多相关文章
随机推荐
- P1433 吃奶酪
题目描述 房间里放着n块奶酪.一只小老鼠要把它们都吃掉,问至少要跑多少距离?老鼠一开始在(0,0)点处. 输入输出格式 输入格式: 第一行一个数n (n<=15) 接下来每行2个实数,表示第i块 ...
- 详解Android Activity生命周期
转载注明来自: http://www.cnblogs.com/wujiancheng/ 一.正常情况下Activity的生命周期: Activity的生命周期大概可以归为三部分 整个的生命周期:o ...
- 未找到框架“.NETFramework,Version=v4.5”的引用程序集
问题描述 一般是在编译的时候会出现这样子的问题, 问题原因: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETF ...
- 内存管理总结-autoreleasePool
转自其他 序言 无论是在MRC时期还是ARC时期,做过开发的程序员都接触过autoreleasepool.尽管接触过但本人对它还不是很了解.本文只是将自己的理解说出来.在内存管理的文章中提到了OC的内 ...
- C#运用存储过程新增一条记录并返回自动生成的ID
@Hcy黄灿奕:http://blog.sina.com.cn/iihcy 前言: 1.存储过的好处: 存储过程相对于其他的数据库访问方法有以下的优点: (1)重复使用.存储过程可以重复使用,从而可以 ...
- day21-4 菱形继承问题(类的查找顺序)
目录 菱形继承问题 经典类(了解) 新式类 mro方法 菱形继承问题 在Python中子类可以同时继承多个父类,如A(B,C,D) 如果继承关系为非菱形结构,则会按照先找B这一条分支,然后再找C这条分 ...
- windows开发错误
2018/07/16: 1.问题: 代码: list <int> listN; error C2065:'list' : undeclared identifier 我已经#include ...
- JavaSE-13 内部类
学习要点 内部类的定义 内部类的应用 内部类 定义 Java的一个类中包含着另一类. A类和B类是C类的外部类.B类是C类的外部类.A类也称为顶层类. 如何使用内部类 public class MyF ...
- IO 双引号 输出 输入
#! /usr/bin/perl use strict;use warnings; print "\n---------<STDIN>_store_into_an_array_a ...
- Java中创建对象的内存图
所有人都知道面向对象思想,Java中的对象的创建在内存中是如何创建的,传智播客的视频看了一遍,把一些讲解的比较清晰的内容记录下来,方便记忆的更加深刻,Java中创建对象的过程,首先要理解JVM中栈.堆 ...