码迷,mamicode.com
首页 > 其他好文 > 详细

PTA ----- 最长对称子串

时间:2020-04-20 23:44:54      阅读:67      评论:0      收藏:0      [点我收藏+]

标签:lse   img   har   ++   子串   image   continue   mic   strlen   

技术图片

#include <stdio.h>
#include <string.h>
#define MAXS 1001

int main(void) 
{
    char input[MAXS], result[MAXS];
    int str_length, i, j, k, max_length = 0;
    gets(input);
    str_length = strlen(input);
    for (i = 1; i <= str_length; i++)
    {  
        for (j = 0; j < str_length + 1 - i; j++) 
        {
            for (k = 0; k < i / 2; k++) 
            {
                if (input[j + k] != input[j + i - k - 1]) 
                {
                    break;
                }
            }
            if (k < i / 2)
            {
                continue;
            }
            else 
            {
                max_length = i;
            }
        }
    }
    printf("%d\n", max_length);
    return 0;
}

PTA ----- 最长对称子串

标签:lse   img   har   ++   子串   image   continue   mic   strlen   

原文地址:https://blog.51cto.com/14737345/2488848

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!