练习使用字符串函数了。

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. mysql删除和修改数据报错1175

    当用MySQL Workbench进行数据库的批量更新时,执行一个语句会碰到以下错误提示: Error Code: 1175 You are using safe...without a WHERE ...

  2. Android之LinkedHashMap实现LRU

    先看下LinkedHashMap的数据结构图 对于LinkedHashMap而言,它继承与HashMap.底层使用哈希表与双向链表来保存所有元素.其基本操作与父类HashMap相似,它通过重写父类相关 ...

  3. Http Pipeline详细分析(下)

    Http Pipeline详细分析(下) 文章内容 接上面的章节,我们这篇要讲解的是Pipeline是执行的各种事件,我们知道,在自定义的HttpModule的Init方法里,我们可以添加自己的事件, ...

  4. MVC中使用Unity Ioc Container

    ASP.NET MVC中使用Unity Ioc Container   写在前面 安装Unity 添加服务层 IArticleRepository类型映射 服务注入到控制器 Global.asax初始 ...

  5. Object Pool

    设计模式之美:Object Pool(对象池)   索引 意图 结构 参与者 适用性 效果 相关模式 实现 实现方式(一):实现 DatabaseConnectionPool 类. 意图 运用对象池化 ...

  6. 在一个view类里面获取viewcontroller

    - (UIViewController *)viewController {     for (UIView* next = [selfsuperview]; next; next = next.su ...

  7. 简单的mvc之二:蜿蜒的管线

    关于系列的第二篇,在管线与路由之间犹豫了很久,最终选择了管线—为免于盲人摸象的困惑. 管线的位置在哪里呢?webform,mvc以及web api都架构于asp.net平台上,管线则是asp.net的 ...

  8. .net mvc页面UI之Jquery博客日历控件

    摘要:最近在做一个博客系统,其他需要用到博客日历控件,网上搜索了很多资料,其中大部分都是javascript的,经过总结使用jquery实现了博客日历效果.代码如下: 原文链接转载请注明:http:/ ...

  9. synchronized和volatile的使用

    synchronized和volatile的使用 一步一步掌握线程机制(三)---synchronized和volatile的使用 现在开始进入线程编程中最重要的话题---数据同步,它是线程编程的核心 ...

  10. Kemaswill 机器学习 数据挖掘 推荐系统 Ranking SVM 简介

    Ranking SVM 简介 排序一直是信息检索的核心问题之一,Learning to Rank(简称LTR)用机器学习的思想来解决排序问题(关于Learning to Rank的简介请见我的博文Le ...