练习使用字符串函数了。

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)的更多相关文章

  1. leetcode:Longest Palindromic Substring(求最大的回文字符串)

    Question:Given a string S, find the longest palindromic substring in S. You may assume that the maxi ...

  2. 【BZOJ2555】SubString(后缀自动机,Link-Cut Tree)

    [BZOJ2555]SubString(后缀自动机,Link-Cut Tree) 题面 BZOJ 题解 这题看起来不难 每次要求的就是\(right/endpos\)集合的大小 所以搞一个\(LCT\ ...

  3. 【SPOJ】Longest Common Substring(后缀自动机)

    [SPOJ]Longest Common Substring(后缀自动机) 题面 Vjudge 题意:求两个串的最长公共子串 题解 \(SA\)的做法很简单 不再赘述 对于一个串构建\(SAM\) 另 ...

  4. String的substring()用于截取字符串

    substring() 用于返回一个字符串的子字符串,即截取字符串功能. substring()常用的重载方法如下: substring(int beginIndex,int endIndex) 意思 ...

  5. substring()的用法和注意事项

    作者原创:转载请注明出处 substring()方法的作用为截取字符串,其有两种用法: 分别如下: substring(int beginIndex);这个的作用为截取从beginindex位置处的元 ...

  6. 拦截导弹 (NYOJ—79) 最长字串问题 (NYOJ—17)

    这是到动态规划的题目,属于有顺序的0 1 背包问题: 代码: #include<stdio.h> #include<string.h> ][]; //d[i][j] ]; in ...

  7. [LeetCode] Longest Palindromic Substring(manacher algorithm)

    Given a string S, find the longest palindromic substring in S. You may assume that the maximum lengt ...

  8. csu 1305 Substring (后缀数组)

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1305 1305: Substring Time Limit: 2 Sec  Memory Limi ...

  9. 算法_Longest Palindromic Substring(寻找最长回文字串)

    题目:Given a string S, find the longest palindromic substring in S. You may assume that the maximum le ...

随机推荐

  1. 基于嵌入式OS的任务设计-----任务划分

    在<前后台系统VS嵌入式OS,何时该上OS?>一文中介绍了何时应该将OS应用于嵌入式设计中,本文将介绍基于OS的任务设计,一般来说,应用程序设计包括两个方面,一个是业务逻辑的设计,另一个是 ...

  2. SZU:G34 Love code

    Judge Info Memory Limit: 32768KB Case Time Limit: 10000MS Time Limit: 10000MS Judger: Normal Descrip ...

  3. JS数量输入控件

    JS数量输入控件 很早看到kissy首页 有数量输入控件,就随便看了下功能 感觉也不怎么难 所以也就试着自己也做了一个, 当然基本的功能和他们的一样,只是用了自己的编码思想来解决这么一个问题.特此给大 ...

  4. 运动检测(前景检测)之(二)混合高斯模型GMM

    运动检测(前景检测)之(二)混合高斯模型GMM zouxy09@qq.com http://blog.csdn.net/zouxy09 因为监控发展的需求,目前前景检测的研究还是很多的,也出现了很多新 ...

  5. Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY'

    The error that occurs is:Fatal error: Undefined class constant 'MYSQL_ATTR_USE_BUFFERED_QUERY' in /w ...

  6. 框架的设计之IRepository还是IRepository<T>

    [Yom框架]漫谈个人框架的设计之[是IRepository还是IRepository<T>]? 前言                                            ...

  7. springMVC3学习(八)--全局的异常处理

    在springMVC的配置文件中: <bean id="exceptionResolver" class="org.springframework.web.serv ...

  8. C#线程同步(转)

    线程同步 在应用程序中使用多个线程的一个好处是每个线程都可以异步执行.对于 Windows 应用程序,耗时的任务可以在后台执行,而使应用程序窗口和控件保持响应.对于服务器应用程序,多线程处理提供了用不 ...

  9. jstl标签的fmt:formatDate格式化日期 String to Date

    使用fmt函数需在jsp中引入 <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" ...

  10. 跨站脚本攻击(Cross‐Site Scripting (XSS))

    跨站脚本攻击(Cross‐Site Scripting (XSS)) 跨站脚本攻击(Cross‐Site Scripting (XSS)) XSS(Cross Site Script)跨站脚本攻击.是 ...