zoj 2744

来源:互联网 发布:阿里云怎么群发短信 编辑:程序博客网 时间:2024/06/15 22:50
#include<stdio.h>
#include
<stdlib.h>
#include
<string.h>
    
char a[5001];
    
int leng;
    
int count ;
   
void len(char *p)
    
{
       
while(*p)
       
{leng ++;    
        p 
++;
       }

      
    }

void isPalindromes(int b,int i)
{
     
    
     
int k = i;
             
     
if(a[b]==a[i])
     
{
            count 
++;
             
            
while(-->= 0&&++< leng)
              
{
               
if(a[b]==a[i])
               count 
++
               
else return;            
              }

     }

    
}

int main()
{

    
while(scanf("%s",a)!=EOF)
    
{
          
int j;
          count 
=0;
          leng 
= 0;
          len(a);
          
int k =0;
          
for(j = 1; j <= 2++ j)
          
{
                
for(k = 0; k <= leng - j; k ++)
                
{
                      isPalindromes(k,k
+j);
                 
                }

       
              
          }

     
          count 
+= leng;  
           printf(
"%d ", count);          
    }

    system(
"pause");
    
return 0;
    }

//对两个三个进行判断回文,是的话再扩展出去,但是时间还是太长了 ,还可以优化 

 最快的那个家伙0.02

我的是0.10..汗一个

 

原创粉丝点击