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 ...
随机推荐
- helloWord
helloWord!!! 在cnblogs安家了
- requirejs的config及optimizer r.js配置
1.怎么处理require.js这些不需要被合并的东西 所有appDir中的文件都会先copy到dir文件中,进行压缩,然后根据build.js中的配置进行相应的合并,包括img等:2.样式合并后原来 ...
- 一键部署mono 免费空间
一键部署mono 免费空间支持c# 再也不担心伙食费换空间了 一直以来 部署mono 都是很头疼的事情 因为是我在是不熟悉非win环境,今天偶然发现这个项目,挺好的,分享下 https://githu ...
- ASP.NET Web Api构建基于REST风格的服务实战系列教程
使用ASP.NET Web Api构建基于REST风格的服务实战系列教程[十]——使用CacheCow和ETag缓存资源 系列导航地址http://www.cnblogs.com/fzrain/p/3 ...
- MVC应用程序请求密码的功能1
MVC应用程序请求密码的功能(一) 经过一系列的练习,实现了会员注册<MVC会员注册>http://www.cnblogs.com/insus/p/3439599.html,登录<M ...
- JS函数实现金额小写转大写
///<summery>小写金额转化大写金额</summery> function AmountLtoU(amount) { if (isNaN(amount) || amou ...
- 【C#】聊聊不需要记密码的密码管理补充帖 —— 具体实现
开篇第一句话,就是“小白继续,有实际经验的兄弟们可以洗洗睡了”,因为这个 Lite 版是个实验性的实现,也由于水平原因源码不忍直视,所以如果你坚持看完了,请留下宝贵意见. 以下,干货: 基本模式: 程 ...
- javascript中字符串常用操作整理
javascript中字符串常用操作整理 字符串的操作在js中非常频繁,也非常重要.以往看完书之后都能记得非常清楚,但稍微隔一段时间不用,便会忘得差不多,记性不好是硬伤啊...今天就对字符串的一些常用 ...
- Lucene全文检索(一)
全文检索的概念 1.从大量的信息中快速.准确的查找要的信息2.收索的内容是文本信息3.不是根据语句的意思进行处理的(不处理语义)4.全面.快速.准确是衡量全文检索系统的关键指标.5.搜索时英文不区分大 ...
- js 获取页面内链接
今天有同学问如何用 JS 正则表达式获取一段文本中的超链接,并对超链接进行处理,想了几分钟,写了下面的代码: var re = /https?:\/\/[\w\.:~\-\d\/]+(?:\?[\w\ ...