Savelyev_Vyacheslav

4 lab c++

Oct 21st, 2020 (edited)
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. using namespace std;
  2.  
  3. // <function of task condition>
  4. void TotalMin();  // uvelichvaet obiem coda, luchshe bez  "function of task condition"
  5. TotalMin( int leftTop, int middle, int rightBottom, int n) {
  6.     if (  (leftTop>middle) && (rightBottom>middle)  )   {
  7.         n++;
  8.         return n;
  9.     }
  10. }
  11. int MinSearch();
  12. MinSearch(int leftTop, int middle, int rightBottom, int i, int j) {
  13.     if (  (leftTop>middle) && (rightBottom>middle)  )   {
  14.         cout<<"IndexMin(i,j) - "<<j<<" "<<i<<endl;
  15.         cout<<" ZnachenieMin - "<<middle<<endl;
  16.     }
  17. }
  18.  
  19. //  </function of task condition>
  20.  
  21. int main() {
  22.     int nrow=4, ncol=4;
  23.     int* n = new int;
  24.     //< sozdast massiv i pamyt>
  25.     int **a = new int*[nrow];
  26.     for (int i = 0; i < nrow; i++) {
  27.         a[i] = new int[ncol];
  28.     }
  29.     //< /sozdast massiv i pamyt>
  30.  
  31.     int i,j;
  32.     int leftTop, middle, rightBottom;
  33.     int key;
  34. tryAgain:
  35.     cout<<"1 - zadat massiv"<<endl;
  36.     cout<<"2 - podschet min cisel"<<endl;
  37.     cout<<"3 - Podschit mines(chisla menshe 0)"<<endl;
  38.     cout<<"4 - Chistka pamayti"<<endl;
  39.     cout<<"5 - Vyvod  min chisel"<<endl;
  40.     cout<<"6 - Exit"<<endl;
  41.     cin>>key;
  42.  
  43.     //////////////////////////
  44.     if (key==1) {
  45.         cout<<"Set elements:"<<endl;
  46.         for(i=0; i<nrow; i++)
  47.             for(j=0; j<ncol; j++) cin>>a[i][j];
  48.     }
  49.     /////////////////////////
  50.  
  51.     int mines = 0;
  52.     *n=0;// kollich min chisel
  53.  
  54.     for(i=0; i<nrow; i++) {
  55.         for(j=0; j<ncol; j++) {
  56.  
  57.             if (a[i][j]<0) {
  58.                 mines++;
  59.             }
  60.  
  61.             if ( ((i-1)<0) || ((j-1)<0) || ((i+1)==nrow) || ((j+1)==ncol)) { // uslovie pogranichnyh neopredelynostey
  62.                 continue;
  63.             } else {
  64.                 leftTop = a[i-1][j-1];
  65.                 middle = a[i][j];
  66.                 rightBottom = a[i+1][j+1];
  67.                 if (key==5) {
  68.                     MinSearch(leftTop, middle, rightBottom, i, j); // poisk znachen po usloviu
  69.                 }
  70.                 *n = TotalMin(leftTop, middle, rightBottom, *n);    // poisk summy znacheniy
  71.  
  72.             }
  73. //           delete arr[i];
  74.         }
  75.     }
  76.     if (key==2) {
  77.         cout<<"Total min(chisla usliviya 'i-1>i<i+1') "<<*n<<endl;
  78.     }
  79.  
  80.     if (key==3) {
  81.         cout<<"Total mines(chisla otritsatelnye)  "<<mines<<endl;
  82.     }
  83.     if (key==4) {
  84.         delete n;
  85.         //<udalit pamayt>
  86.         for (int i = 0; i < nrow; i++) {
  87.             delete [] a[i];
  88.         }
  89.         delete [] a;
  90.         //</udalit pamayt>
  91.     }
  92.     if (key==6) {
  93.         //<udalit pamayt>
  94.         for (int i = 0; i < nrow; i++) {
  95.             delete [] a[i];
  96.         }
  97.         delete [] a;
  98.         //</udalit pamayt>
  99.         return 0;
  100.     }
  101.     goto tryAgain;
  102.  
  103. }
Add Comment
Please, Sign In to add comment