Pagini recente » Rating Teddy Nita (nita_teddy) | Cod sursa (job #1637379) | Cod sursa (job #1808118) | Cod sursa (job #1408081) | Cod sursa (job #637820)
Cod sursa(job #637820)
#include <fstream>
#include <string>
using namespace std;
string s;
int L[505][30], D[505][30];
int main(){
ifstream fin("palm.in");
ofstream fout("palm.out");
int i, n, j;
fin >> s;
n = s.size();
for(i = 0; i < n; ++i){
if(i)
for(j = 1; j <= 'z' - 'a' + 1; ++j)
L[i][j] = L[i - 1][j];
L[i][s[i] - 'a' + 1] = L[i][s[i] - 'a'] + 1;
}
for(i = n - 1; i >= 0; --i){
for(j = 1; j <= 'z' - 'a' + 1; ++j)
D[i][j] = D[i + 1][j];
D[i][s[i] - 'a' + 1] = D[i][s[i] - 'a'] + 1;
}
int max = 0;
// for(i = 0; i < n; ++i){
// for(j = 1; j <= 'z' - 'a' + 1; ++j)
// if(D[i][j])
// fout << i << " " << (char)(j + 'a' - 1) << " " << D[i][j] << '\n';
// }
for(i = 0; i< n; ++i)
if(L[i][s[i] -'a' + 1] == D[i][s[i] - 'a' + 1] && max < L[i][s[i] - 'a'])
max = L[i][s[i] - 'a'];
fout << max * 2 + 1 << '\n';
return 0;
}