Cod sursa(job #636646)

Utilizator AndrewTheGreatAndrei Alexandrescu AndrewTheGreat Data 19 noiembrie 2011 22:09:44
Problema PalM Scor 30
Compilator cpp Status done
Runda .com 2011 Marime 0.98 kb
#include <iostream>
#include <fstream>
#include <string.h>
#define i64 long long

using namespace std;

const int nmax = 1 << 9;
char S[nmax];

int main()
{
    ifstream in("palm.in");
    ofstream out("palm.out");

    in.getline(S, nmax);

    i64 M = 1, L = strlen(S), i, C, p, j;
    for(i = 1; i < L; i++)
    {
        if(S[i - 1] == S[i])
        {
            C = 2;
            p = i << 1;
            for(j = i + 1; j < L && p - j - 1 >= 0; j++)
                if(S[j] == S[p - j - 1] && S[j] <= S[j - 1])
                    C += 2;
                else break;
            if(M < C)
                M = C;
        }
        if(S[i - 1] == S[i + 1] && S[i - 1] <= S[i])
        {
            C = 3;
            p = i << 1;
            for(j = i + 2; j < L && p - j >= 0; j++)
                if(S[j] == S[p - j] && S[j] <= S[j - 1])
                    C += 2;
                else break;
            if(M < C)
                M = C;
        }
    }

    out << M;

    return 0;
}