第四届河南省ACM SUBSTRING 字符串处理
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 字符串处理的更多相关文章
- 第四届河南省ACM 序号互换 进制转换
序号互换 时间限制: 1 Sec 内存限制: 128 MB 提交: 41 解决: 19 [提交][状态][讨论版] 题目描述 Dr.Kong设计了一个聪明的机器人卡多,卡多会对电子表格中的单元格坐 ...
- 第四届河南省ACM 表达式求值 栈
表达式求值 时间限制: 1 Sec 内存限制: 128 MB 提交: 14 解决: 7 [提交][状态][讨论版] 题目描述 Dr.Kong设计的机器人卡多掌握了加减法运算以后,最近又学会了一些简 ...
- 第四届河南省ACM 节能 区间DP
1001: 节 能 时间限制: 1 Sec 内存限制: 128 MB 提交: 21 解决: 9 [提交][状态][讨论版] 题目描述 Dr.Kong设计的机器人卡多越来越聪明.最近市政公司交给卡多 ...
- [河南省ACM省赛-第四届] 序号互换 (nyoj 303)
相似与27进制的转换 #include<iostream> #include<cstdio> #include<cstring> #include<strin ...
- [河南省ACM省赛-第四届] 表达式求值(nyoj 305)
栈的模拟应用: #include<iostream> #include<cstdio> #include<cstring> #include<string&g ...
- js substr和substring字符串截取
substr(start,length)第一个参数是开始位置(注:start的开始是从0开始,看到好多博客上面是从1开始,在火狐和谷歌执行了一下是从0开始),第二个参数是截取字符串的长度(可以省略,表 ...
- Longest Palindromic Substring - 字符串中最长的回文字段
需求:Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
- 2017 ACM 字符串的本质
题目:http://acm.hdu.edu.cn/showproblem.php?pid=2017 思路:思考字符串和数字的本质区别是什么. 今天先是试着做了一个完全背包的题目,发现自己还是不会做,弄 ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
随机推荐
- LeetCode 136. Single Number (落单的数)
Given an array of integers, every element appears twice except for one. Find that single one. Note:Y ...
- component及刚体rigidbody用法
关于getcomponent函数,rigidbody(2d)的嵌套关系及用法 1.getcomponent函数 在unity中脚本可以看成是可定义的组件,我们经常要访问同一对象或不同对象中的脚本,可以 ...
- 异常详细信息: Abp.AbpException: No language defined!
程序运行后,出现错误:No language defined! 解决方法: 1.检查是否已创建数据库,若未创建则在程序包管理控制台执行命令:Update-Database 2.检查表AbpLangua ...
- Windows环境下多线程编程原理与应用读书笔记(5)————互斥及其应用
<一>互斥的同步机制 思想:当一个线程获得互斥量了后,其他所有要获取同一个互斥量的线程都处于阻塞状态,直到第一个线程释放互斥量为止. 设想几个线程竞争同一个互斥量,其中一个线程获得了互斥量 ...
- Knight Moves
Problem Description A friend of you is doing research on the Traveling Knight Problem (TKP) where yo ...
- hdu 4717 Tree2cycle(树形DP)
Tree2cycle Time Limit: 15000/8000 MS (Java/Others) Memory Limit: 102400/102400 K (Java/Others)Tot ...
- hive中UDF、UDAF和UDTF使用
Hive进行UDF开发十分简单,此处所说UDF为Temporary的function,所以需要hive版本在0.4.0以上才可以. 一.背景:Hive是基于Hadoop中的MapReduce,提供HQ ...
- 还原NuGet程序包
官网:https://msdn.microsoft.com/zh-cn/magazine/hh547106.aspx 在获取团队中的项目或者下载他人的项目Demo后,运行项目有时会提示某些dll找不到 ...
- Formatting the event object
尽量将IE与DOM函数事件对象不同的性质或方法转成DOM标准 EventUtil.formatEvent = function (oEvent) { if (isIE && ...
- Python 字典和json的本质区别(个人理解)
个人理解:字典和json显示的时候差不多,但是数据类型不同(如下图): 字典的类型是字典dict json的类型是字符串str 接口测试是传参数payload时有时候是传的字符串,应该将payload ...