Pagini recente »
Istoria paginii runda/test_2/clasament
|
Istoria paginii runda/cerc_8_1/clasament
|
Istoria paginii runda/runda_pregatire/clasament
|
Istoria paginii utilizator/klinbzt
|
Cod sursă (job #376659)
Cod sursă (job
#376659)
#include <fstream>
#include <cstring>
using namespace std;
ifstream in("bart.in");
ofstream out("bart.out");
char ch[500001],ch1[500001],ch2[500001];
bool ok=false;
int l=1;
int main()
{
in>>ch;
while(true)
{
strncpy(ch1,ch,l);
strncpy(ch2,ch+l,500000-l);
while(strstr(ch2,ch1)-ch2!=0 && l<strlen(ch2))
{
l+=strstr(ch2,ch1)-ch2;
strncpy(ch1,ch,l);
strncpy(ch2,ch+l,500000-l);
}
if(l>=strlen(ch2))
{
out<<ch1;
return 0;
}
int k=1;
while(strstr(ch2,ch1)-ch2==0)
{
k++;
if(k*l>strlen(ch))
break;
strncpy(ch2,ch+k*l,500000-k*l);
}
if(k==strlen(ch)/l)
{
out<<ch1;
return 0;
}
l++;
}
return 0;
}