• zoj 2744 Palindromes


    Palindromes

    Time Limit: 1 Second      Memory Limit: 32768 KB

    A regular palindrome is a string of numbers or letters that is the same forward as backward. For example, the string "ABCDEDCBA" is a palindrome because it is the same when the string is read from left to right as when the string is read from right to left.

    Now give you a string S, you should count how many palindromes in any consecutive substring of S.

    Input

    There are several test cases in the input. Each case contains a non-empty string which has no more than 5000 characters.

    Proceed to the end of file.

    Output

    A single line with the number of palindrome substrings for each case.

    Sample Input

    aba
    aa

    Sample Output

    4
    3


    Author: LIU, Yaoting


    Source: Zhejiang Provincial Programming Contest 2006
    Submit    Status
    //1858692 2009-05-07 18:43:31 Accepted  2744 C++ 730 24624 Wpl 
    #include <iostream>
    #define MAX 5002
    using namespace std;
    char str[MAX];
    bool mark[MAX][MAX];
    int main()
    {
        
    int i,j,len,r,sum;
        
    while(scanf("%s",str+1)!=EOF)
        {
            len
    =strlen(str+1);
            sum
    =0;
            
    for(r=1;r<=len;r++)
                
    for(i=1;i<=len-r+1;i++)
                {
                    j
    =i+r-1;
                    mark[i][j]
    =false;
                    
    if(str[i]==str[j])
                    {
                        
    if(r==1)
                        {
                            sum
    ++;
                            mark[i][j]
    =true;
                        }
                        
    if(r==2)
                        {
                            mark[i][j]
    =true;
                            sum
    ++;
                        }
                        
    else if(mark[i+1][j-1])
                        {
                            mark[i][j]
    =true;
                            sum
    ++;
                        }
                    }
                }
            printf(
    "%d\n",sum);
        }
        
    return 0;
    }
  • 相关阅读:
    eclipse远程调试Tomcat方法(转)
    Django表单字段汇总
    Django表单API详解
    django使用表单
    django自定义模板标签和过滤器
    django人类可读性
    django特殊的标签和过滤器
    Django内置模板标签
    Django模板语言详解
    django 动态生成PDF文件
  • 原文地址:https://www.cnblogs.com/forever4444/p/1452565.html
Copyright © 2020-2023  润新知