ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1723. Sandro's Book

WA3 I cant find the error
Posted by Arturo 27 Jul 2013 05:49
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
char v[53];int ch[53];
char vi[53][5],*punt=NULL,vf[53],vc[53],vp[53],*a,vt[53],chr[3];
int maxl=0,maxt=0,k,b,max2,l=0;
int n,j=0,i,ind;

main()
{
gets(v);
n=strlen(v);
if(n==1){cout<<v;}
else{

for(i=0;i<n-1;i++)
{   // carga inicial
vi[i][0]=v[i] ;
vi[i][1]=v[i+1] ;
ch[i]=0;

}

for(i=0;i<n-1;i++)
{
punt=strstr(v,vi[i]);

if(punt!=NULL)
{
ch[punt-v]++;

}
}
for(i=0;i<n-1;i++)
{

if(ch[i]>maxt)
{
maxt=ch[i];
ind=i;

}

}
strcpy(vc,vi[ind]);
strcpy(vp,v);

punt=strstr(v,vi[ind]);
i=0;
strcpy(vf,vi[ind]);
if (maxt!=0)
{  while(1)

{

b=1;

punt=strstr(v,vf);
chr[0]=punt[2+l];

strcat(vf,chr);

k=2+l;
k++;
l++;
if(l==strlen(punt))break;
max2=0;
strcpy(vp,v);
while(1)
{
punt=strstr(vp,vf);

if(punt!=NULL)
{

j=strlen(punt);

for(i=0;i<j-1;i++)
{
vp[i]=punt[i+1];
}
vp[i]='\0';

max2++;
if (max2>=maxt)
{
maxt=max2;
strcpy(vc,vf);
b=0;

}

}
if(punt==NULL)break;

}
if(b==3) break;

}

}
cout<<vc;

}}