第四届河南省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, ...
随机推荐
- web 开发中的路由是什么意思
路由: 就是一个路径的解析,根据客户端提交的路径,将请求解析到相应的控制器上 从 URL 找到处理这个 URL 的类和函数
- python常用模块上篇
python常见模块 分两篇分别介绍下述模块 time模块 random模块 hashlib模块 os模块 sys模块 logging模块 序列号模块 configparser模块 re模块 time ...
- 关于docker使用的几个小问题(一)
由于刚接触docker踩了几个坑,希望本文对网瘾少年有所帮助. Docker分CE版(社区版)和EE版(商用版),具体安装流程参考文档介绍,在此不再赘述.下面分Windows和Linux分别踩坑: 一 ...
- ABAP开发实用快捷键
在程序中注释代码往往受输入法影响,看了别人的一篇博客,结合自己的测试发现用如下方法可以直接注释源代码不受输入法影响 添加注释:ctrl + space + < 去掉注释:ctrl + space ...
- 转载——yum源的超级简单配置
1.先挂载光盘. 使用命令"mount -o loop /dev/sr0 /mnt/cdrom".如果使用命令"mount -o loop /dev/cdrom ...
- Leftmost Digit
Problem Description Given a positive integer N, you should output the leftmost digit of N^N. Input ...
- AngularJS学习篇(一)
AngularJS 使用 表达式 把数据绑定到 HTML. AngularJS 表达式 AngularJS 表达式写在双大括号内:{{ expression }}. AngularJS 表达式把数据绑 ...
- 针对数据量较大的表,需要进行跨库复制,采用navcat 实现sqlite数据库跨数据库的数据表迁移 [转载]
2014年12月13日 14:36 新浪博客 (转自http://www.cnblogs.com/nmj1986/archive/2012/09/17/2688827.html) 需求: 有两个不同的 ...
- HTML学习笔记 CSS学习选择器案例 第五节 (原创) 参考使用表
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Breadth-first search 算法(Swift版)
在讲解Breadth-first search 算法之前,我们先简单介绍两种数据类型Graph和Queue. Graph 这就是一个图,它由两部分组成: 节点, 使用圆圈表示的部分 边, 使用线表示的 ...