Cod sursa(job #2556363)

Utilizator ivddabDabelea Ioana-Viviana ivddab Data 24 februarie 2020 20:44:08
Problema Prefix Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <fstream>
#include <string>
using namespace std;
ifstream f("prefix.in");
ofstream g("prefix.out");
int t,n,ok,max1,i,poz,j;
string s;
int main()
{
    f>>t;
    while(t!=0){
        t--;
        f>>s;
        n=s.size();
        ok=0; max1=-1; i=1;
        while(i<n){
            if(ok==0){
              if(s[0]==s[i]){
                ok=1; poz=i-1; j=0;
              }
            }
            if(ok==1){
              if(s[j]==s[i]){
                if((j+1)%(poz+1)==0) max1=max(max1,i);
                j++;
              } else { ok=0; i--; }
            }
            i++;
        }
        g<<max1+1<<'\n';
    }
    return 0;
}