hdu 1544 求字符串回文
#include <stdio.h>
#include <string.h>
int pal(char *str)
{
int len = strlen(str);
int l, r;
int ans = len;
for(int i=0; i<len; i++)
{
l = i-1; r = i+1;
while(l >= 0 && r < len && str[l] == str[r])
{l--; r++; ans++;}
l = i; r = i+1;
while(l >= 0 && r < len && str[l] == str[r])
{l--; r++; ans++;}
}
return ans;
}
int main()
{
//freopen("read.txt", "r", stdin);
char str[10000];
while(~scanf("%s", str))
{
printf("%d\n", pal(str));
}
return 0;
}
附件列表