描述 | |
---|---|
知识点 | 字符串,循环,函数,指针,枚举,位运算,结构体,联合体,文件操作,递归 |
运行时间限制 | 10M |
内存限制 | 128 |
输入 | 输入一个字符串 |
输出 | 返回有效密码串的最大长度 |
样例输入 | ABBA |
样例输出 | 4 |
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
//#include "Customer.h"
#define Max(a,b) (a)>(b)?(a):(b)
using namespace std;
int getCatcher(string str, int i)
{
int count1 = 0, count2 = 0;
int pre = i - 1;
int post = i + 1;
while (pre>=0 && post<str.length() && str[pre] == str[post] )
{
pre--;
post++;
}
count1 = post - pre - 1;
pre = i;
post = i + 1;
while (pre >= 0 && post<str.length() && str[pre] == str[post] )
{
pre--;
post++;
}
count2 = post - pre - 1;
return Max(count1, count2);
}
int main()
{
string str;
cin >> str;
int max = 0;
for (int i = 1; i < str.length(); i++)
{
max = Max(max, getCatcher(str, i));
}
cout << max;
return 0;
}