#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(--b >= 0&&++i < 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;
}
// 对两个三个进行判断回文,是的话再扩展出去,但是时间还是太长了 ,还可以优化
#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(--b >= 0&&++i < 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..汗一个