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 ...
随机推荐
- asp.net页面生命周期回顾
---根据一讲师所讲做了一下笔记,仅供参考 会存在些错误 页面声明周期: 1.HttpApplication在第11和第12个事件之间开始了页面声明周期,调用了第8个事件创建实例的pr(Process ...
- css,js工具篇
4. web前端开发分享-css,js工具篇 web前端开发乃及其它的相关开发,推荐sublime text, webstorm(jetbrains公司系列产品)这两个的原因在于,有个技术叫emm ...
- Push Notification总结系列(一)
Notification系列概括: 1.Push Notification简介和证书说明及生成配置 2.Push Notification的iOS处理代码和Provider详解 3.Push Noti ...
- Day3:T3DP T4堆排序
QAQ因为T3的题解说的不是很清楚,但是blogs又不能按照自己想要的顺序排+略有一点强迫症 所以先挖个坑放着,过几天再补上
- golang切片slice
切片slice是引用类型 len()函数获取元素的个数 cap()获取数组的容量 1.申明方式 (1)var a []int 与数组不同的是他不申明长度(2)s2 := make([]int, 3, ...
- C#线程池用法
C#线程池用法 在C#编程语言中,使用线程池可以并行地处理工作,当强制线程和更新进度条时,会使用内建架构的ThreadPool类,为批处理使用多核结构,这里我们来看在C#编程语言中一些关于来自Syst ...
- [笔记] OS X and iOS 内核开发
一.KEXT包的安全性说明 KEXT 程序包及其包含的所有文件及文件夹必须属于 root 用户(用户 id 是 0) KEXT 程序包及其包含的所有文件及文件夹必须属于 wheel 组(组 id 是 ...
- javascript遍历select下拉框判断其中值是否与指定值相等
用jquery多了,就忘了原生的js是如何写的了,还需要多加巩固. 需求:jsp回显一select下拉框.选中指定值. 用户点击修改 该select进行已有值回显.有两种解决方法 一.js中获取用户的 ...
- node.js系列笔记之node.js初识《一》
node.js系列笔记之node.js初识<一> 一:环境说明 1.1 Linux系统CentOS 5.8 1.2 nodejs v0.10.15 1.3 nodejs源码下载地址 htt ...
- 【最新】让快捷方式 实现相对路径——非.bat方式实现
快捷方式一般是使用绝对路径的,但并不是不能使用相对路径,系统为普通用户考虑一般默认使用绝对路径,这样的结果是:只要目标文件(不论是文件夹.程序.文档,也包括快捷方式)绝对位置不变,我们创建的快捷方式基 ...