(nyoj308)substring
来源:互联网 发布:齐鲁商品交易软件操作 编辑:程序博客网 时间:2024/05/06 14:32
Substring
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
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
这题很多人跪在题意上,表示我也贡献了一次wa,就是没读懂题意,这道题的意思是找最长子串反过来还是其子串,不是找最长的回文串,举个例子
abcdeba输出ab,因为ab是可以反过来的最长子串;
代码:
#include<iostream>#include<cstdio>#include<string>#include<string.h>#include<algorithm>#include<cmath>#include<vector>#include<cstring>#include<stdlib.h>#include<ctype.h>using namespace std;int main(){ string ch1; int t,maxlen=1,ans; cin>>t; while(t--) { cin>>ch1; string ch2=ch1; reverse(ch2.begin(),ch2.end()); bool flag=0; for(int i=ch2.size();i>0;i--) { for(int j=0;j<=ch2.size()-i;j++) { string v=ch1.substr(j,i); if(ch2.find(v)!=string::npos) { cout<<v<<endl; flag=1; break; } } if(flag==1)break; } }}
0 0
- (nyoj308)substring
- NYOJ308-Substring
- NYOJ308 Substring (DP)
- nyoj308-Substring(LCS(河南第四届省赛A题))
- nyoj308 Substring(第四届河南省程序设计大赛)
- nyoj308(最长公共子串)
- 1020(encode substring)
- Substring
- Substring
- substring
- substring
- Substring
- substring
- substring
- substring
- substring
- substring
- substring
- 截取某张图片的一部分
- android GridView 用法
- Unity手游之路<十>自动寻路Navmesh之跳跃,攀爬,斜坡
- iOS中代码支持多国语言切换的实现(Xcode5+iOS7)
- 文件上传
- (nyoj308)substring
- IT人才需求前景甚好 软件开发市场依然走俏
- Tabhost最纯净的实现方式
- Linux下/proc目录简介
- 每个程序员都必读的10篇文章
- IOS 开发的一些细节(持续更新)
- Unity手游之路<九>自动寻路Navmesh之高级主题
- 打招呼
- Python中关于导入(import)语句的使用说明