题解 | #密码截取#
密码截取
http://www.nowcoder.com/practice/3cd4621963e8454594f00199f4536bb1
#include <stdio.h>
#include <string.h>
#define MAX(a, b) ((a > b) ? (a) : (b))
static int CheckSymCipher(const char *str, int start, int end)
{
for (int i = start, j = end; i <= j; i++, j--) if (str[i] != str[j]) return -1;
return 0;
}
static char g_string[2501] = {0};
int main(int argc, char** argv)
{
while (gets(g_string) != NULL) {
int max = 1, len = strlen(g_string);
for (int i = 0; i < len; i++) for (int j = len - 1; j > i; j--) {
if (CheckSymCipher(g_string, i, j) == 0) { max = MAX(max, j - i + 1); break; }
}
printf("%d\n", max);
}
return 0;
}