Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- bool stringaInversa (string a,string b);
- bool controlloMatrice (string matrice[][3],int M,int N);
- int main()
- {
- const int M=3,N=3;
- string matrice[][M]={{"nano","mano","sano"},
- {"cano","tano","naso"},
- {"iano","lano","onas"}};
- cout << "sto confrontanto le parole per ogni colonna della matrice" << endl;
- cout << "se 1 allora in quella colonna ci sono due parole invertite : " << controlloMatrice(matrice,N,M) << endl;
- return 0;
- }
- bool stringaInversa (string a,string b)
- {
- int luna;
- luna=a.length();
- if (luna!=int(b.length())) return false;
- else
- {
- int i=0;
- while (i<luna)
- {
- if (a[i]!=b[luna-i-1]) return false;
- i++;
- }
- return true;
- }
- }
- bool controlloMatrice (string matrice[][3],int N,int M)
- {
- int i,k=0,j;
- while (k<M)
- {
- i=0;
- while (i<N)
- {
- j=i+1;
- while (j<N)
- {
- cout << "confronto " << matrice[i][k] << " con " << matrice[j][k] << endl;
- if (stringaInversa(matrice[i][k],matrice[j][k])) return true;
- j++;
- }
- i++;
- }
- k++;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement