SUBSTRING

时间限制: 1 Sec  内存限制: 128 MB

提交: 17  解决: 5

[提交][状态][讨论版]

题目描述

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 tiebreaker 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

提示

来源

题目大意:

这道题很容易直接堪称求最长回文子串的题目。但是题目中有一句关键的话。The substring and its reversal may overlap partially or completely.

所以,实际题目的意思是将找到的子串在原串中翻转仍旧出现在原串中。审题很重要。

思路:

字符串最多50个字符,直接爆就好了。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main() {
int t;
cin>>t;
while(t--) {
string s;
cin>>s;
int s_len=s.length();
string ss;
string str;
for(int i=0;i<s_len;i++) {
for(int j=1;j<=s_len-i;j++) {
ss=s.substr(i,j);
reverse(ss.begin(),ss.end());
if(s.find(ss)!=-1) {
if(ss.length()>str.length()) {
reverse(ss.begin(),ss.end());
str=ss;
}
}
}
}
cout<<str<<endl;
}
return 0;
}

第四届河南省ACM SUBSTRING 字符串处理的更多相关文章

  1. 第四届河南省ACM 序号互换 进制转换

    序号互换 时间限制: 1 Sec  内存限制: 128 MB 提交: 41  解决: 19 [提交][状态][讨论版] 题目描述 Dr.Kong设计了一个聪明的机器人卡多,卡多会对电子表格中的单元格坐 ...

  2. 第四届河南省ACM 表达式求值 栈

    表达式求值 时间限制: 1 Sec  内存限制: 128 MB 提交: 14  解决: 7 [提交][状态][讨论版] 题目描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简 ...

  3. 第四届河南省ACM 节能 区间DP

    1001: 节 能 时间限制: 1 Sec  内存限制: 128 MB 提交: 21  解决: 9 [提交][状态][讨论版] 题目描述 Dr.Kong设计的机器人卡多越来越聪明.最近市政公司交给卡多 ...

  4. [河南省ACM省赛-第四届] 序号互换 (nyoj 303)

    相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...

  5. [河南省ACM省赛-第四届] 表达式求值(nyoj 305)

    栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...

  6. js substr和substring字符串截取

    substr(start,length)第一个参数是开始位置(注:start的开始是从0开始,看到好多博客上面是从1开始,在火狐和谷歌执行了一下是从0开始),第二个参数是截取字符串的长度(可以省略,表 ...

  7. Longest Palindromic Substring - 字符串中最长的回文字段

    需求:Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...

  8. 2017 ACM 字符串的本质

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=2017 思路:思考字符串和数字的本质区别是什么. 今天先是试着做了一个完全背包的题目,发现自己还是不会做,弄 ...

  9. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

随机推荐

  1. 【20171025早】alert(1) to win 练习

    本人黑绝楼,自称老黑,男,25岁,曾经在BAT工作过两年,但是一直都是底层人员,整天做重复性工作,甚敢无趣,曾和工作十年之久的同事聊天,发现对方回首过往,生活是寡淡如水,只有机械性工作.旋即老黑毅然决 ...

  2. macOs升级到10.13.1Beta || JAVA升级到最新版之后PhpStorm菜单栏问题

    macOs升级到10.13.1Beta || JAVA升级到最新版之后PhpStorm菜单栏会消失,估计不止出现在PhpStorm,一系列jetbrains的产品可能都会有这个问题,包括eclipis ...

  3. Go语言之三驾马车

    作者:唐郑望,腾讯后台开发 工程师商业转载请联系腾讯WeTest获得授权,非商业转载请注明出处.  WeTest 导读 Go语言的三个核心设计: interface | goroutine | cha ...

  4. python爬虫xpath

    又是一个大晴天,因为马上要召开十九大,北京地铁就额外的拥挤,人贴人到爆炸,还好我常年挤地铁早已练成了轻功水上漂,挤地铁早已经不在话下. 励志成为一名高级测试工程师的我,目前还只是个菜鸟,难得有机会,公 ...

  5. 有两组随机生成的(0~99999)Int32数据A和B,将A按顺序判断在B中是否存在并记录在Boolean型的C中

    http://www.cnblogs.com/asxinyu/p/4504487.html

  6. FATE

    FATE Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissi ...

  7. mysql索引优化建议

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 2.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索 ...

  8. python中pygame模块的Linux下安装过程

    一.使用pip安装Python包 大多数较新的Python版本都自带pip,因此首先可检查系统是否已经安装了pip.在Python3中,pip有时被称为pip3. 1.在Linux和OS X系统中检查 ...

  9. 阿里云ecs遭到频繁的ddos攻击始末

    苦逼熬夜近俩月的时间搞出来个小东东,还指望它能给自己捞点~  结果刚上线没多久就遭到竞争对手疯狂的ddos攻击. 可怜的阿里云默认只能抗住5G的攻击,超出的直接黑洞,也是很无奈,然而能免费抗5G这在国 ...

  10. 5. 监视和ZooKeeper操作

    ZooKeeper中的写入(write)操作是原子性和持久性的. 写入到大多数ZooKeeper服务器上的持久性存储中,可以保证写操作成功. 无论如何,ZooKeeper的最终一致性模型允许读取(re ...