题解 | #最长回文子串#

最长回文子串

http://www.nowcoder.com/practice/12e081cd10ee4794a2bd70c7d68f5507

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    string a;
    while(getline(cin,a))
    {
        string b;
        int c=0;
       reverse(b.begin(),b.end());
        for(int i=0;i<a.length();i++)
        {
            for(int j=1;j<a.length()-i+1;j++)
            {
                  b=a.substr(i,j);
                 reverse(b.begin(),b.end());
                       if(a.substr(i,j)== b)
                       {
                         if(j>c)
                         {
                             c=j;
                         }    
               }
            }
        }
        cout<<c;
    }
    return(0);
}
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务