hipo 4 最长回文
来源:互联网 发布:水仙花数java 编辑:程序博客网 时间:2024/06/06 04:11
#include<stdio.h>#include<iostream>#include<string.h>#include<algorithm>using namespace std;#define N 1000005char str[2 * N + 2] = { 0 };char st[N] = { 0 };int p[2 * N + 2] = { 0 };int func(char* s){int nn = strlen(s);int n = 2 * nn + 2;str[0] = '$';//str首位置赋值$ for (int i = 0; i <= nn; i++){str[2 * i + 2] = st[i];str[2 * i + 1] = '#';}int ans = -999;int mx = 0;//mx用来记录p[i]中到达的最右端的值 int id;//id用来记录p[i]延长至最右端的下标i for (int i = 1; i<n; i++){if (mx > i)p[i] = min(p[2 * id - i], mx - i);//不太明白,待深思。。。。 elsep[i] = 1;while (str[i - p[i]] == str[i + p[i]])p[i]++;if (mx < i + p[i]){mx = i + p[i];id = i;}if (ans < p[i])ans = p[i];}return ans - 1;}int main(){int n;cin >> n;for (int i = 0; i < n; ++i){cin >> st;cout << func(st) << endl;}return 0;}
0 0
- hipo 4 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 最长回文
- 例题3-4 最长回文子串
- HIPO图
- HIPO图
- 最长回文子串
- 最长回文子串
- 安卓模拟新浪微博随便看看
- 程序员面试、算法研究、编程艺术、红黑树、数据挖掘5大系列集
- DTO与Entity 的区别
- 反射相关类Class说明
- log4net使用详解
- hipo 4 最长回文
- vSphere Client中VM剪贴板交互
- 我的记录
- 每天一个linux命令:touch 命令
- Spark on Yarn: Where Have All the Memory Gone?
- C++学习之多态及重载(overload),覆盖(override),隐藏(hide)的区别
- rar命令行参数
- ASP.NET微信公众号开发实记之一 接入配置
- 监控运维那点事-vsphere