Cod sursa(job #1979845)

Utilizator stefdascalescuStefan Dascalescu stefdascalescu Data 11 mai 2017 15:41:00
Problema PalM Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.68 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("palm.in");
ofstream g("palm.out");
int maxpal=1,ok;
char q[505];
int main()
{
    f>>q;
    int n=strlen(q);
    for(int i=0;i<=n;++i)
        for(int j=i+1;j<n;++j)
            if(q[j]==q[i])
            {
                int b=i+1;
                int e=j-1;
                int ok=0;
                while(q[b]==q[e] && q[b]>=q[b-1]){
                    ++b,--e;
                    if(b>e){
                        ok=1;
                        break;
                    }
                }
                if(ok==1)
                    maxpal=max(maxpal,j-i+1);
            }
    g<<maxpal;
    return 0;
}