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 ...
随机推荐
- w5cValidator【AngularJS】 2.0 版本发布
w5cValidator 插件基于angular原有的表单验证,在原有的基础上扩展了一些错误提示的功能,让大家不用在每个表单上写一些提示信息的模板,专心的去实现业务逻辑. 代码地址:https://g ...
- Windows Live Writer 完成开源并推出开源分支
原文:Announcing Open Live Writer - An Open Source Fork of Windows Live Writer Windows Live Writer是一款发布 ...
- Caliburn Micro框架
Caliburn Micro框架快速上手(WP) 一.使用nuget添加起始工程 二.修改App.xaml文件和App.xaml.cs文件 AppBootstrapper介绍: AppBootst ...
- CODEFORCES #272 DIV2[为填完]
#272是自己打的第一场cf,感觉这一套质量挺棒的,不像后两场略水 //先附上A,B,C的题解,因为离noip只剩下一点时间了,所以之后不一定还刷cf,暂且就先放上前三题好了 A题目大意忘了.懒得看, ...
- 2013.5.A
题1 高低位交换 [问题描述] 给出一个小于2^32的正整数.这个数可以用一个32位的二进制数表示(不足32位用0补足).我们称这个二进制数的前16位为“高位”,后16位为“低位”.将它的高低位交换, ...
- Activity的启动模式与flag详解
Activity有四种加载模式:standard(默认), singleTop, singleTask和 singleInstance.以下逐一举例说明他们的区别: standard:Activity ...
- CSS3:三个矩形,一个宽200px,其余宽相等且自适应满铺
某公司面试题:下图绿色区域的宽度为100%,其中有三个矩形,第一个矩形的宽度是200px,第二个和第三个矩形的宽度相等.使用CSS3中的功能实现它们的布局. 这里要用到的CSS3特性box-flex ...
- 读取同一文件夹下多个txt文件中的特定内容并做统计
读取同一文件夹下多个txt文件中的特定内容并做统计 有网友在问,C#读取同一文件夹下多个txt文件中的特定内容,并把各个文本的数据做统计. 昨晚Insus.NET抽上些少时间,来实现此问题,加强自身的 ...
- LNMP安装与配置
Nginx与apache.lighttp性能综合对比,如下图: 注意:关闭rpm默认安装的apache和mysql 1.准备php函数的rpm包 y ...
- python手记(11)
<form method="POST" action="http://host.com/cgi-bin/test.py"> <p>You ...