河南省第四届ACM程序设计大赛 问题 F: SUBSTRING
来源:互联网 发布:锦衣卫同知是什么官职 编辑:程序博客网 时间:2024/04/27 13:48
问题 F: SUBSTRING
时间限制: 1 Sec 内存限制: 128 MB提交: 30 解决: 22
[提交][状态]
题目描述
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 ABCABAXYZXCVCX
样例输出
ABAXXCVCX
提示
#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;
}
- 河南省第四届ACM程序设计大赛 问题 F: SUBSTRING
- 河南省第四届程序设计大赛--Substring
- nyoj308 Substring(第四届河南省程序设计大赛)
- 问题 A: 序号互换 河南省第四届ACM程序设计大赛
- 河南省第四届ACM程序设计大赛 问题 G: BOBSLEDDING
- NYOJ-308-Substring(第四届河南省程序设计大赛F题(简单状压dp))
- noj 308 Substring (第四届河南省程序设计大赛)
- 第四届河南省程序设计大赛
- 第四节河南省程序设计大赛-NYOJ-308-Substring
- 第四届河南省程序设计大赛 - 部分题解
- 河南省第七届ACM程序设计大赛总结
- 河南省第三届ACM程序设计大赛题解
- 河南省第九届ACM程序设计大赛总结
- 河南省第四届acm省赛 Substring
- 第四届河南省ACM SUBSTRING 字符串处理
- 河南省第四届ACM程序设计大赛(共八道,目前只做两道。待续)
- nyoj 545 第五届河南省程序设计大赛F
- noj 303 序号互换 (第四届河南省程序设计大赛)
- 常用的iOS第三方资源
- 怎么查看某个网站使用什么web服务器及架构
- Linux系统中‘dmesg’命令处理故障和收集系统信息的7种用法
- ShellExecute API函数用法简析
- 【android】:android数据存储之sharedPreferences代码可使用
- 河南省第四届ACM程序设计大赛 问题 F: SUBSTRING
- 数理统计与参数估计
- Linux驱动学习(模块1)
- GOT 班扬叔叔
- 关于任务二的小练习1的总结
- Unable to resolve target 'android-XX'问题
- 当JPA遇上MySQL表名全大写
- poj1068Parencodings
- pull解析