对给定的字符串,本题要求你输出最长对称子串的长度。例如,给定Is PAT&TAP symmetric?,最长对称子串为s PAT&TAP s,于是你应该输出11。

输入格式:

输入在一行中给出长度不超过1000的非空字符串。

输出格式:

在一行中输出最长对称子串的长度。

输入样例:

Is PAT&TAP symmetric?

输出样例:

11
不用算法也可以,可以用马拉车算法。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#define MAX 1000
using namespace std; char s[MAX + ];
char t[MAX * + ] = {'@','#'};
int p[MAX * + ];
int Manacher(char *str) {
int len = strlen(str);
for(int i = ;i <= len;i ++) {
t[i * ] = str[i - ];
t[i * + ] = '#';
}
t[len * + ] = ;
int mi = ,rpoint = ,mr = ;
for(int i = ;t[i];i ++) {
p[i] = i < rpoint ? min(rpoint - i,p[mi * - i]) : ;
while(t[i + p[i]] == t[i - p[i]]) p[i] ++;
if(i + p[i] > rpoint) {
mi = i;
rpoint = i + p[i];
}
if(mr < p[i]) mr = p[i];
}
return mr - ;
}
int main() {
int i = ;
while((s[i] = getchar()) != '\n') i ++;
s[i] = ;
printf("%d",Manacher(s));
}

L2-008 最长对称子串 (25 分)的更多相关文章

  1. L2-008 最长对称子串 (25 分) (模拟)

    链接:https://pintia.cn/problem-sets/994805046380707840/problems/994805067704549376 题目: 对给定的字符串,本题要求你输出 ...

  2. [刷题] PTA 7-64 最长对称子串

    7-64 最长对称子串 我的代码: 1 #include<stdio.h> 2 #include<string.h> 3 #define N 1001 4 5 int main ...

  3. 团体程序设计天梯赛-练习集L2-008. 最长对称子串

    L2-008. 最长对称子串 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 对给定的字符串,本题要求你输出最长对称子串的长度. ...

  4. c语言:最长对称子串(3种解决方案)

    问题描述: 输入一个字符串,输出该字符串中最大对称子串的长度.例如输入字符串:“avvbeeb”,该字符串中最长的子字符串是“beeb”,长度为4,因而输出为4. 解决方法:中序遍历 一,全遍历的方法 ...

  5. L2-008. 最长对称子串(思维题)*

    L2-008. 最长对称子串 参考博客 #include <iostream> using namespace std; int main() { string s; getline(ci ...

  6. pat 团体赛练习题集 L2-008. 最长对称子串

    对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...

  7. L2-008. 最长对称子串

    L2-008. 最长对称子串 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 对给定的字符串,本题要求你输出最长对称子串的长度. ...

  8. PAT L2-008 最长对称子串(模拟字符串)

    对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定Is PAT&TAP symmetric?,最长对称子串为s PAT&TAP s,于是你应该输出11. 输入格式: 输入在一 ...

  9. 天梯赛L2-008 最长对称子串 (字符串处理)

    对给定的字符串,本题要求你输出最长对称子串的长度.例如,给定"Is PAT&TAP symmetric?",最长对称子串为"s PAT&TAP s&quo ...

随机推荐

  1. 派生类时使用private的目的 《私有派生》

    第一:继承方式是public的情况下: 当成员是public的时候,派生类对象可以直接调用基类的这个方法和数据, 当数据是private的时候,派生类的对象不能直接调用之,可以通过调用基类的方法来访问 ...

  2. ID基本操作(标尺,参考线,网格)5.11

    参考线:标尺参考线,分栏参考线,出血参考线.在创建参考线之前确保标尺和参考线都可见.并且选中正确的跨页和页面作为目标, “版面”“创建参考线”可以输入数值创建参考线. 跨页参考线的创建:拖动参考线时鼠 ...

  3. C++ string类insert用法总结

    body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...

  4. relativeURL 相对URL的坑

    我正在尝试实现一个使用RestKit的iOS应用程序.在我迄今为止看到的所有示例中,以下代码用于创建URL: NSURL *baseURL = [NSURL URLWithString:@" ...

  5. Cracking The Coding Interview 5.5

    #include <iostream> #include <vector> using namespace std; int getNum1(int N) { int num= ...

  6. Python自动化必备发送邮件报告脚本详解

    #!/usr/bin/python3# -*- coding:UTF-8 -*-import smtplib#smtplib库主要用来连接第三方smtp库,用来发邮件from email.mime.t ...

  7. centos7配置mysql

    一:mysql安装方法一:yum安装 下载并安装MySQL官方的 Yum Repository https://dev.mysql.com/ cd ~ wget -i -c https://dev.m ...

  8. Centos7部署kubernetes Proxy(七)

    1.配置kube-proxy使用LVS(三个节点都装上去) [root@linux-node1 ssl]# yum install -y ipvsadm ipset conntrack [root@l ...

  9. mybatis学习(二)----对表进行CRUD操作

    一.使用MyBatis对表执行CRUD操作——基于XML的实现 userMapper.xml映射文件如下: <?xml version="1.0" encoding=&quo ...

  10. UBUNTU 测试跑分

    time echo "scale=5000; 4*a(1)" | bc -l -q3.14159265358979323846264338327950288419716939937 ...