Pagini recente » Cod sursa (job #3200552) | Cod sursa (job #3220772) | Cod sursa (job #1261175) | Cod sursa (job #1081808) | Cod sursa (job #2953565)
//https://infoarena.ro/problema/subsir
#include<fstream>
#include<cstring>
#define Dmax 500
std::ifstream f ("subsir.in");
std::ofstream g ("subsir.out");
int i,j,l1,l2,nr,nrmax,k,ok,ii,jj;
char s1[Dmax],s2[Dmax];
int sub[Dmax][Dmax],inceput[Dmax];
int main()
{
f.getline(s1,Dmax);
f.getline(s2,Dmax);
l1=strlen(s1);
l2=strlen(s2);
for(i=0;i<l1;i++)
for(j=0;j<l2;j++)
if(s1[i]==s2[j])
sub[i][j]=1;
for(i=0;i<l1;i++)
for(j=0;j<l2;j++){
nr=0;
ii=i;jj=j;
while(sub[ii++][jj++]==1 && sub[ii+1][jj+1]==1)
nr++;
if(nrmax<nr)
{
nrmax=nr;
k=0;
inceput[k]=j;
}else
if(nrmax==nr){
inceput[++k]=j;
}
}
for(i=0;i<k-1;i++)
for(j=i+1;j<k;j++)
if(inceput[i]==inceput[j])
ok++;
g<<(k-ok)%666013;
f.close();
g.close();
return 0;
}