Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 24th, 2012  |  syntax: C++  |  size: 1.03 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <iostream>
  2. using namespace std;
  3. const int N=4;
  4. void ricerca_conta_righe(int a[N][N],int x,int i,int j,int& nc,int k,int ri,int col)
  5. {
  6.     while (col<N && nc<k)
  7.     {
  8.         if (x==a[ri][col])
  9.         nc++;
  10.         col++;
  11.     }
  12. }
  13. bool ricerca_conta_colonne(int a[N][N],int x, int i, int j,int k)
  14. {
  15.     int nc,nr=0,ri=0,col;
  16.     bool b=false;
  17.     while (ri<N )
  18.     {
  19.         nc=0;
  20.         col=0;
  21.         ricerca_conta_righe(a,x,i,j,nc,k,ri,col);
  22.         if (nc==k)
  23.         nr++;
  24.         ri++;
  25.     }
  26.     if (nr==k)
  27.     b=true;
  28.     return b;
  29. }
  30.  
  31.  
  32. int main () {
  33.     int a[N][N]={(1,2,2,3),
  34.                  (1,4,5,2),
  35.                  (2,5,2,2),
  36.                  (2,2,3,2)};
  37.     int i,j,x,k;
  38.     bool b;
  39.     cout<<"Inserire un intero positivo k>=2 \n";
  40.     cin >>k;
  41.     for (i=0;i<N;i++)
  42.     {
  43.         for (j=0;j<N;j++)
  44.         {
  45.             x=a[i][j];
  46.             b=ricerca_conta_colonne (a,x,i,j,k);
  47.         }
  48.     }
  49.     if (b==true)
  50.     cout <<"vero";
  51.     else cout<<"falso";
  52.     return 0;
  53. }