NYOJ 308 Substring 字符串处理问题
来源:互联网 发布:淘宝怎么设置id限购 编辑:程序博客网 时间:2024/04/28 21:50
这道题我也是花了好长时间才写出来,本来想出来方法了,带式写着太麻烦,所以就一直没写,一直想用string类写的,但是由于对string类中的函数不清楚,所以基本上把每个函数都试了一遍,,,,好在写出来了。这道题题意容易搞错,去年省赛时就有许多队伍理解错题意了,此题不是让求最长回文子串的,而是让求一个最长的子串,该子串的逆串也在原串中。举个例子来说,abcdba,若是求最长回文子串,应为a,对此题来说,应为ab,因为ab的逆串ba也在原串中。题目:
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 ABCABAXYZXCVCX
- 样例输出
ABAXXCVCX
#include <iostream>#include <cstdio>#include <string>#include <algorithm>#include <string.h>using namespace std;int main(){//freopen("1.txt","r",stdin);int numcase;scanf("%d",&numcase);string s1,s2,s3;while(numcase--){ cin>>s1; s2=s1; int max=0; reverse(s2.begin(),s2.end()); int len=s1.size(); for(int i=0;i<len;++i){ for(int j=1;j<=len-i;++j){ string::size_type pos=s2.find(s1.substr(i,j)); if(pos!=string::npos){ if(max<j){ max=j;s3=s1.substr(i,j); } } } } cout<<s3<<endl;}return 0;}
- NYOJ 308 Substring 字符串处理问题
- nyoj 308 substring (最长逆序字符串)
- NYOJ 308 Substring
- NYOJ 308题 Substring
- nyoj-308-Substring
- nyoj 308 Substring
- nyoj 308 Substring
- nyoj 308 Substring
- NYOJ 308-Substring【模拟】
- NYOJ 308 Substring
- nyoj 308 Substring
- NYOJ Substring--308
- nyoj 308 Substring
- nyoj 308 Substring
- NYOJ 308 Substring
- nyoj 658 字符串右移(字符串处理问题)
- NYOJ—308—Substring
- Longest Palindromic Substring(字符串处理)
- 【GLSL教程】(二)在OpenGL中使用GLSL
- Instagram揭秘:牛逼的图片服务都在用哪些装备和技术
- 把c语言中的声明用程序翻译成通俗的语言
- 指针使用注意事项
- 第八周实验报告任务1
- NYOJ 308 Substring 字符串处理问题
- linux给firefox安装flash插件
- oracle中的sequence
- startActivityForResult 用法
- 2、对象和类型
- PL/SQL0.1——块嵌套与变量范围
- huffman树和huffman编码
- php中创建JSON
- webbrowser显示html