首页 > 其他 > 详细

九度oj 1528 最长回文子串

时间:2015-05-18 18:24:32      阅读:172      评论:0      收藏:0      [点我收藏+]

原题链接:http://ac.jobdu.com/problem.php?pid=1528 
小白书上的做法,不过这个还要简单些。。。

技术分享
 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 using std::max;
 7 const int Max_N = 200010;
 8 char ret[Max_N];
 9 void solve() {
10     int i, j, ans = 0, n = strlen(ret);
11     for (i = 0; i < n; i++) {
12         for (j = 0; i >= j && i + j < n; j++) {
13             if (ret[i - j] != ret[i + j]) break;
14             ans = max(ans, j << 1 | 1);
15         }
16         for (j = 0; i >= j && i + j + 1 < n; j++) {
17             if (ret[i - j] != ret[i + j + 1]) break;
18             ans = max(ans, (j << 1) + 2);
19         }
20     }
21     printf("%d\n", ans);
22 }
23 int main() {
24 #ifdef LOCAL
25     freopen("in.txt", "r", stdin);
26     freopen("out.txt", "w+", stdout);
27 #endif
28     while (gets(ret)) solve();
29     return 0;
30 }
View Code

 

九度oj 1528 最长回文子串

原文:http://www.cnblogs.com/GadyPu/p/4512186.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!