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 ...
随机推荐
- Android之LinkedHashMap实现LRU
先看下LinkedHashMap的数据结构图 对于LinkedHashMap而言,它继承与HashMap.底层使用哈希表与双向链表来保存所有元素.其基本操作与父类HashMap相似,它通过重写父类相关 ...
- [转载]John Burkardt搜集的FORTRAN源代码
Over the years, I have collected, modified, adapted, adopted or created a number of software package ...
- [置顶] 如何使用c3p0+spring连接oracle数据库
1. 首先是jdbc.properties属性文件的编写,便于数据库移植: datasource.driverClassName=oracle.jdbc.driver.OracleDriver dat ...
- SZU:A25 Favorite Number
Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Number Only Ju ...
- 使用MVCJqGrid
使用MVCJqGrid的心得 最近公司网站进行升级,项目要用.net mvc,mysql和轻量级orm框架dapper.由于美工页面出不来啊,让我先写简单写写后台的列表,同事说用MvcJqGrid ...
- C# 求精简用一行代码完成的多项判断 重复赋值
C# 求精简用一行代码完成的多项判断 重复赋值 哈哈,说实话,个人看着这么长的三元操作也麻烦,但是我也只想到了这样三元判断句中执行方法体能够写到一行,追求的终极目的是,用一行实现这个过程,而且简单,由 ...
- [RM 状态机详解3]RMContainer状态机详解
摘要 RMContainer是RM内部维护的Container状态.事实上,在RM的调度器中,会维护着一个liveContainers列表,保存着所有存活着的Container信息.图1显示RMCon ...
- IOS学习之路二十四(custom 漂亮的UIColor)
下面简单列举一下漂亮的和颜色,大家也可以自己依次试一试选出自己喜欢的. 转载请注明 本文转自:http://blog.csdn.net/wildcatlele/article/details/1235 ...
- 多个AsynceTask无法同时运行的现象分析
关于这篇博客所提到的问题是在一段再简单不过的代码中意外出现的.当时我使用了两个不同'AsyncTask'帮助我执行两个需要在后台执行任务.并且这两个'AsyncTask'几乎是同时运行的.原本会正常运 ...
- 拦截所有AJAX调用,重点处理服务器异常
拦截所有AJAX调用,重点处理服务器异常 背景 上篇文章http://www.cnblogs.com/happyframework/p/3241063.html介绍了如何以AOP的形式处理服务器异常, ...