Cod sursa(job #636322)

Utilizator cristianalex81Cristian Alexandru cristianalex81 Data 19 noiembrie 2011 18:48:18
Problema PalM Scor 0
Compilator cpp Status done
Runda .com 2011 Marime 1.12 kb
#include <fstream>
#define dim 502

using namespace std;

char a[dim];
int n;

int subsirmax()
{
    bool flag;
    int len = 1, start = 0, best = 1;
    int i,j;
    for(i=1;i<n;i++)
    {
        if ((a[i]==a[i-1]+1)||(a[i]==a[i-1])) //pot adauga la subsir
        {
            len++;
            flag = true;
            for (j=1;j<len;j++) //check for munte
                if (a[i-j]!=a[i+j])
                {
                    flag = false;
                    break;
                }

            if (flag)//we have a good sequence
            {
                if (len>best)
                    best = len;
                //jump over this sequence
                i +=len -1;
                start = i+1;
                len = 1;
            }
        }
        else
        {
            start = i;
            len = 1;
        }
    }
    if (best==1)
        return 1;
    else
        return best*2 - 1;
}
int main()
{
    ifstream f ("palm.in");
    ofstream g ("palm.out");
    char x;
    while (f>>x)
    {
        a[n]=x;
        n++;
    }
    g<<subsirmax()<<"\n";
    f.close();
    g.close();
    return 0;
}