Advertisement
Emanuele_Bruno

Esame 11

Dec 5th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. bool stringaInversa (string a,string b);
  7. bool controlloMatrice (string matrice[][3],int M,int N);
  8.  
  9. int main()
  10. {
  11.     const int M=3,N=3;
  12.     string matrice[][M]={{"nano","mano","sano"},
  13.                          {"cano","tano","naso"},
  14.                          {"iano","lano","onas"}};
  15.     cout << "sto confrontanto le parole per ogni colonna della matrice" << endl;
  16.     cout << "se 1 allora in quella colonna ci sono due parole invertite : " << controlloMatrice(matrice,N,M) << endl;
  17.     return 0;
  18. }
  19.  
  20. bool stringaInversa (string a,string b)
  21. {
  22.     int luna;
  23.     luna=a.length();
  24.     if (luna!=int(b.length())) return false;
  25.     else
  26.     {
  27.         int i=0;
  28.         while (i<luna)
  29.         {
  30.             if (a[i]!=b[luna-i-1]) return false;
  31.             i++;
  32.         }
  33.         return true;
  34.     }
  35. }
  36.  
  37. bool controlloMatrice (string matrice[][3],int N,int M)
  38. {
  39.     int i,k=0,j;
  40.     while (k<M)
  41.     {
  42.         i=0;
  43.         while (i<N)
  44.         {
  45.             j=i+1;
  46.             while (j<N)
  47.             {
  48.                 cout << "confronto " << matrice[i][k] << " con " << matrice[j][k] << endl;
  49.                 if (stringaInversa(matrice[i][k],matrice[j][k])) return true;
  50.                 j++;
  51.             }
  52.             i++;
  53.         }
  54.         k++;
  55.     }
  56.     return false;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement