Substring (nyoj 308)
练习使用字符串函数了。
1、字串的反转也是它的字串,2、最长,3、最先出现
string:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
int t, n;
string s;
cin>>t;
while(t--){
cin>>s;
int n = s.size();
; i--){//枚举长度
; j+i-<n; j++){//枚举开端
string ts = s.substr(j, i);
reverse(ts.begin(), ts.end());
if(s.find(ts) != string::npos){
cout<<s.substr(j, i)<<endl;
goto here;
}
}
}
here: ;
}
;
}
char[],用时是上面的一半
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 52
char s[N];
char ts[N];
int main()
{
int t, n;
scanf("%d", &t);
while(t--){
scanf("%s", s);
int n = strlen(s);
; i--){//枚举长度
; j+i-<n; j++){//枚举开端
strncpy(ts, s+j, i);
ts[i] = '\0';
reverse(ts, ts+i);
if(strstr(s, ts) != NULL){
strncpy(ts, s+j, i);
ts[i] = '\0';
cout<<ts<<endl;
goto here;
}
}
}
here: ;
}
;
}
Substring (nyoj 308)的更多相关文章
- leetcode:Longest Palindromic Substring(求最大的回文字符串)
Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...
- 【BZOJ2555】SubString(后缀自动机,Link-Cut Tree)
[BZOJ2555]SubString(后缀自动机,Link-Cut Tree) 题面 BZOJ 题解 这题看起来不难 每次要求的就是\(right/endpos\)集合的大小 所以搞一个\(LCT\ ...
- 【SPOJ】Longest Common Substring(后缀自动机)
[SPOJ]Longest Common Substring(后缀自动机) 题面 Vjudge 题意:求两个串的最长公共子串 题解 \(SA\)的做法很简单 不再赘述 对于一个串构建\(SAM\) 另 ...
- String的substring()用于截取字符串
substring() 用于返回一个字符串的子字符串,即截取字符串功能. substring()常用的重载方法如下: substring(int beginIndex,int endIndex) 意思 ...
- substring()的用法和注意事项
作者原创:转载请注明出处 substring()方法的作用为截取字符串,其有两种用法: 分别如下: substring(int beginIndex);这个的作用为截取从beginindex位置处的元 ...
- 拦截导弹 (NYOJ—79) 最长字串问题 (NYOJ—17)
这是到动态规划的题目,属于有顺序的0 1 背包问题: 代码: #include<stdio.h> #include<string.h> ][]; //d[i][j] ]; in ...
- [LeetCode] Longest Palindromic Substring(manacher algorithm)
Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...
- csu 1305 Substring (后缀数组)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1305 1305: Substring Time Limit: 2 Sec Memory Limi ...
- 算法_Longest Palindromic Substring(寻找最长回文字串)
题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...
随机推荐
- Metadata是.NET平台的核心灵魂--(转载)
(转载)Metadata是.NET平台的核心灵魂 July 7th, 2010 jzli Leave a comment Go to comments 网友来信:李老师,您好!我参加过你去年到我们公司 ...
- 在Idea中调试ant应用
Ant调试 Ant调试 ant 是一种非常方便的打包,部署的工具,通过ant,可以一键构建整个项目,虽然MVN也支持这种功能,但是MVN混杂了package管理的功能,并且不是很自由,学习成本比较高. ...
- JavaScript实例技巧精选(14)—动态变化背景颜色
>>点击这里下载完整html源码<< 这是截图: 网页背景颜色随时间变化,核心代码如下: <SCRIPT LANGUAGE="JavaScript"& ...
- awk学习点滴
1,常量 ARGC:命令行参数个数 包括awk本身命令,但awk的自带option不算在内. ARGV:命令行参数数组 ARGV[0]是awk本身,其他依次提取就好. $ awk -F ' ' 'BE ...
- Asycn/Await 异步编程
Asycn/Await 异步编程初窥(二) 经过总过4天的学习和实践,做完了 WinForm 下 .Net 4.5 的基本异步应用,实现了一个 Http 协议下载的测试程序,为以后使用 .Net ...
- Java读书笔记1
Java逍遥游记读书笔记 前言 必须先来一句,这是入门级别,高手勿喷~ 写Android的时候总有一些语句不是很理解,其实大部分是Java的内容,所以想系统的学下Java. 这本书——<Java ...
- LIS 最长递增子序列问题
一, 最长递增子序列问题的描述 设L=<a1,a2,…,an>是n个不同的实数的序列,L的递增子序列是这样一个子序列Lin=<aK1,ak2,…,akm>,其中k1< ...
- Iveely Search Engine 0.4.0 的发布
千呼万唤始出来,Iveely Search Engine 0.4.0 的发布 经过无数个夜晚的奋战,以及无数个夜晚的失眠,Iveely Search Engine 0.4.0 终于熬出来了,这其中 ...
- scribefire 多博客管理利器 安装详解
scribefire 多博客管理利器 安装详解 一.ScribeFire介绍 ScribeFire 是 Firefox (火狐浏览器)上著名的博客写作工具,目前已跨平台支持多浏览器(Firefox,C ...
- Arduino 各种模块篇 摇杆模块
Arduino的另外几种模块,我们常见的joystick摇杆模块. 用起来很爽,摇杆 有X,Y轴可调 这里有一篇非常想尽的示例代码: http://www.geek-workshop.com/foru ...