# 河南省第四届ACM程序设计大赛 问题 F: 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 <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f

char str[110],s1[110],str2[110];
char Max[110];
int main()
{
int N,i,j,k;
while(scanf("%d",&N)!=EOF)
{
while(N--)
{
scanf("%s",str);
int x=0;
for(i=strlen(str)-1;i>=0;i--)
str2[x++]=str[i];
str2[x]='\0';

int len=(int)strlen(str);
memset(Max,0,sizeof(Max));
for(i=0;i<len;i++)
{
for(j=0;j<=i;j++)
{
int t=0;
for(k=j;k<=i;k++)
{
s1[t++]=str[k];
}
s1[t]='\0';
if( strstr(str2,s1)!=NULL)
{
if((int)strlen(s1)>(int)strlen(Max))
{
strcpy(Max,s1);
}
}
}
}
printf("%s\n",Max);
}
}
return 0;
}

#### NYOJ305 表达式求值(河南省第四届ACM省赛)

2017-04-19 21:24:19

#### 第四届河南省程序设计大赛

2016-05-29 11:11:08

#### 河南省第十届ACM程序设计大赛参赛心得

2017-05-09 21:19:41

#### 河南省第十一届ACM程序设计大赛榜单

2018-05-28 12:01:51

#### 河南省第十届ACM赛题

2017-05-08 16:56:17

#### 河南省第五届大学生程序设计大赛最终排名

2012-05-14 13:24:21

#### 2017河南省第十届ACM大学生程序设计竞赛总结

2017-05-08 15:02:16

#### 2016河南省第九届ACM程序设计竞赛【正式赛真题】

2016-07-19 11:09:26

#### 关于河南省第十一届ACM程序设计大赛

2018-05-28 13:46:08

#### 河南省ACM程序设计大赛历年真题

2018年01月30日 492KB 下载