Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <string>
- #include <cstdlib>
- using namespace std;
- /*
- * ESERCIZIO
- * Scrivere un metodo che prenda in input una matrice A ed un array B entrambi di stringhe e
- * restituisca un boolean che indichi se esiste in A una coppia di stringhe la cui concatenazione,
- * privata delle occorrenze del carattere 'a', sia presente in B.
- *
- * By Trupia Ludovico
- */
- const int COLONNE = 7 ;
- void alloca_Matrice_Stringa ( string matrice[][COLONNE] , int righe );
- void stampa_Matrice ( string matrice[][COLONNE] , int righe );
- bool conc_Verifica ( string matrice[][COLONNE] , int righe , string vettore[] );
- void stampa_Vettore ( string vettore[] );
- void alloca_Vettore ( string vettore[] );
- int main()
- {
- srand( time ( NULL ));
- int righe ;
- cout << endl << " Che lunghezza ha la matrice A? \n [RIGHE]// ";
- cin >> righe;
- string A[righe][COLONNE], B[COLONNE] ;
- cout << endl;
- alloca_Matrice_Stringa ( A , righe );
- stampa_Matrice ( A , righe );
- cout << endl << "//////////////////////////////////////////" << endl ;
- alloca_Vettore ( B );
- stampa_Vettore ( B );
- cout << endl << "//////////////////////////////////////////" << endl << endl ;
- if ( conc_Verifica ( A , righe , B ) )
- {
- cout << endl << endl << " !!!!!Esiste una concatenazione uguale!!!!! ";
- }
- else
- {
- cout << endl << endl << " !!!!!NON Esiste una concatenazione uguale!!!!! ";
- }
- return 0;
- }
- void alloca_Matrice_Stringa ( string matrice[][COLONNE] , int righe )
- {
- int n = 0;
- char consonanti[16] = {'b','c','d','f','g','h','l','m','n','p','q','r','s','t','v','z'};
- char vocali[5] = {'a','e','i','o','u'};
- for( int j = 0; j < righe; j++)
- {
- for ( int k = 0 ; k < COLONNE ; k++)
- {
- n = ((rand() % 4) + 2) * 2;
- for( int i = 0; i < n; i++)
- {
- if( i % 2 == 0 )
- {
- matrice[j][k] += consonanti[rand()%16];
- // cout << consonanti[rand()%16];
- }
- else
- {
- matrice[j][k] += vocali[rand()%5];
- //cout << vocali[rand()%5];
- }
- }
- }
- }
- }
- void stampa_Matrice ( string matrice[][COLONNE] , int righe )
- {
- for ( int i = 0 ; i < righe ; i++ )
- {
- cout << endl;
- for ( int j = 0 ; j < COLONNE ; j++ )
- {
- cout << matrice[i][j] << " " ;
- }
- cout << endl;
- }
- }
- void alloca_Vettore ( string vettore[] )
- {
- int n = 0;
- char consonanti[16] = {'b','c','d','f','g','h','l','m','n','p','q','r','s','t','v','z'};
- char vocali[4] = {'e','i','o','u'};
- for( int j = 0; j < COLONNE; j++)
- {
- n = ((rand() % 4) + 2) * 2;
- for( int i = 0; i < n; i++)
- {
- if( i % 2 == 0 )
- {
- vettore[j] += consonanti[rand()%16];
- // cout << consonanti[rand()%16];
- }
- else
- {
- vettore[j] += vocali[rand()%5];
- //cout << vocali[rand()%5];
- }
- }
- }
- }
- void stampa_Vettore ( string vettore [])
- {
- cout << endl;
- for ( int i = 0 ; i < COLONNE ; i++ )
- {
- cout << vettore[i] << " ";
- }
- cout << endl;
- }
- bool conc_Verifica ( string matrice[][COLONNE] , int righe , string vettore[] )
- {
- string concatenazione = "";
- for ( int i = 0 ; i < righe ; i ++ )
- {
- for ( int j = 0 ; j < COLONNE-1 ; j++ )
- {
- for ( int k = j+1 ; k < COLONNE ; k++ )
- {
- cout << endl << endl << "########## j - " << j << " | k - " << k << endl << endl;
- for ( int f = 0 ; f < matrice[i][j].length() ; f++ )
- {
- if ( matrice[i][j].at(f) != 'a' )
- {
- concatenazione += matrice[i][j].at(f);
- cout << concatenazione << " ";
- }
- }
- for ( int f = 0 ; f < matrice[i][k].length() ; f++ )
- {
- if ( matrice[i][k].at(f) != 'a' )
- {
- concatenazione += matrice[i][k].at(f);
- cout << concatenazione << " ";
- }
- }
- for ( int f = 0 ; f < COLONNE ; f++ )
- {
- int v = 0;
- for ( int l = 0 ; l < vettore[f].length() ; l++ )
- {
- if ( concatenazione.at(v) == vettore[f].at(l) )
- {
- v++;
- }
- else
- {
- v = 0;
- }
- if ( v == concatenazione.length() )
- {
- return true;
- }
- }
- }
- concatenazione = "";
- }
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement