练习使用字符串函数了。

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. sql like 时间需要做转换

    EG: where Convert(varchar(100),[字段名],120) like '2010-10-10%'

  2. SpringMVCURL请求到Action的映射规则

    SpringMVC学习系列(3) 之 URL请求到Action的映射规则 在系列(2)中我们展示了一个简单的get请求,并返回了一个简单的helloworld页面.本篇我们来学习如何来配置一个acti ...

  3. Effective C++(13) 用对象管理资源

    问题聚焦: 从这条准则开始,都是关于资源管理的. 资源,一旦用了它,将来必须还给系统. 本条准则,基于对象的资源管理办法,建立在C++的构造函数,析构函数和拷贝函数(拷贝构造函数和重载赋值操作符)的基 ...

  4. 浅谈DevExpress<五>:TreeList简单的美化——自定义单元格,加注释以及行序号

    今天就以昨天的列表为例,实现以下效果:预算大于110万的单元格突出显示,加上行序号以及注释,如下图:

  5. [Usaco2008 Feb]Eating Together麻烦的聚餐[最长不下降子序列]

    Description 为了避免餐厅过分拥挤,FJ要求奶牛们分3批就餐.每天晚饭前,奶牛们都会在餐厅前排队入内,按FJ的设想所有第3批就餐的奶牛排在队尾,队伍的前端由设定为第1批就餐的奶牛占据,中间的 ...

  6. intellij idea 学习

      intellij idea是一个java的ide.由jetbrain开发.     intellij idea快捷键 快捷键 说明 备注 Ctrl+N 快速导航到类 类似于Resharper中的C ...

  7. 关于SourceTree License

    SourceTree 是免费软件,但是需要到官网注册一下账号以获得免费的License 官网地址:https://id.atlassian.com/login?application=mac& ...

  8. 获取时间SQL函数语句

    1.获取时间 获取当天的数据 where  DATEDIFF (DD, 数据库中时间的字段 ,GETDATE())=0 查询24小时内的 where  DATEDIFF (HH, 数据库中时间的字段 ...

  9. Memcache的一些学习

    Memcache的一些学习 首先,Memcache是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.它通过在内存中缓存数据和对象来减少读取数据库的次数,从而提供动态.数据库驱动 ...

  10. java微信平台,发源码

    最近写了一个微信平台的架构,采用servlet + spring3.0 + hibernate4.1.整体架构由我负责建设,我尽可能的把业务模块分出来.趁着刚搭好的框架,留着这版.代码是大部份都由其他 ...