il codice è cosi:
codice:
void HashMap::LCS (string vocabolo)
{
for (iteratore=dMap.begin(); iteratore != dMap.end() ;iteratore++)
{
string secondotermine = iteratore -> second ;
int lungh1=vocabolo.size(), lungh2=secondotermine.size();
int i=0,j=0; int array[100][100];
for (int i=0;i<=lungh1;i++)
{
array[i][0]=0;
}
for (int j=0;j<=lungh2;j++)
{
array[0][j]=0;
}
for (int i=1;i<=lungh1;i++)
{
for (int j=1;j<=lungh2;j++)
{
if (vocabolo[i]==secondotermine[j])
{
array[i][j]=array[i-1][j-1]+1;
}
else if (array[i-1][j]>=array[i][j-1])
{
array[i][j]=array[i-1][j];
}
else {
array[i][j]=array[i][j-1];
}
}
}
i=lungh1, j=lungh2;
if (array[i][j] >= 3)
{
dMap2.insert(pair<int,string>(array[i][j],secondotermine));
}
}
for (iteratore2=dMap2.end(); iteratore2 != dMap2.begin() ;iteratore2--)
{
cout << "Forse intendevi " << iteratore2 -> second<<"?"<<endl;
}
}
Ho seri dubbi sul for finale infatti il programma crasha.
Allora secondo me l'ultimo if è fatto bene perchè in pratica tuttle parole con x occorenze le salva nella dMap2 con il valore dell'occorrenza. Poi alla fine il ciclo dovrebbe stamparle tutte ma nn ho capito bene come accedere agli elementi della multimap. Poi vabbe credo manchi il fatto che alla fine dell'algoritmo devo svuotarla la dMap2, giusto?
Cmq cm posso risolvere il problema della stampa?
Grazie ancora