Pagini recente » Cod sursa (job #3195330) | Cod sursa (job #941806) | Cod sursa (job #1862776) | Cod sursa (job #1437069) | Cod sursa (job #2738814)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
string A,B;
#define DIM 1001
int n,m,l_max,cons,rasp,nr_indici;
int indici[DIM];
int matrice[DIM][DIM];
ifstream fin("lungimesubsircomunmaximal.in");
ofstream fout("lungimesubsircomunmaximal.out");
void lungcom()
{
for(int i=0;i<=n;i++)
{
for(int j=0;j<=m;j++)
{
if( i==0|| j==0)
{
matrice[i][j]=0;
}
else if(A[i-1]==B[j-1])
{
matrice[i][j]=matrice[i-1][j-1]+1;
rasp=max(rasp,matrice[i][j]);
if(rasp==min(n,m))
{
indici[nr_indici++]=j-rasp;
}
}
else
{
matrice[i][j]=0;
}
}
}
}
int main()
{
fin>>A>>B;
n=A.length(),m=B.length();
lungcom();
fout<<nr_indici<<'\n';
for(int i=0;i<nr_indici;i++)
{
fout<<indici[i]<<" ";
}
}