Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- // <function of task condition>
- void TotalMin(); // uvelichvaet obiem coda, luchshe bez "function of task condition"
- TotalMin( int leftTop, int middle, int rightBottom, int n) {
- if ( (leftTop>middle) && (rightBottom>middle) ) {
- n++;
- return n;
- }
- }
- int MinSearch();
- MinSearch(int leftTop, int middle, int rightBottom, int i, int j) {
- if ( (leftTop>middle) && (rightBottom>middle) ) {
- cout<<"IndexMin(i,j) - "<<j<<" "<<i<<endl;
- cout<<" ZnachenieMin - "<<middle<<endl;
- }
- }
- // </function of task condition>
- int main() {
- int nrow=4, ncol=4;
- int* n = new int;
- //< sozdast massiv i pamyt>
- int **a = new int*[nrow];
- for (int i = 0; i < nrow; i++) {
- a[i] = new int[ncol];
- }
- //< /sozdast massiv i pamyt>
- int i,j;
- int leftTop, middle, rightBottom;
- int key;
- tryAgain:
- cout<<"1 - zadat massiv"<<endl;
- cout<<"2 - podschet min cisel"<<endl;
- cout<<"3 - Podschit mines(chisla menshe 0)"<<endl;
- cout<<"4 - Chistka pamayti"<<endl;
- cout<<"5 - Vyvod min chisel"<<endl;
- cout<<"6 - Exit"<<endl;
- cin>>key;
- //////////////////////////
- if (key==1) {
- cout<<"Set elements:"<<endl;
- for(i=0; i<nrow; i++)
- for(j=0; j<ncol; j++) cin>>a[i][j];
- }
- /////////////////////////
- int mines = 0;
- *n=0;// kollich min chisel
- for(i=0; i<nrow; i++) {
- for(j=0; j<ncol; j++) {
- if (a[i][j]<0) {
- mines++;
- }
- if ( ((i-1)<0) || ((j-1)<0) || ((i+1)==nrow) || ((j+1)==ncol)) { // uslovie pogranichnyh neopredelynostey
- continue;
- } else {
- leftTop = a[i-1][j-1];
- middle = a[i][j];
- rightBottom = a[i+1][j+1];
- if (key==5) {
- MinSearch(leftTop, middle, rightBottom, i, j); // poisk znachen po usloviu
- }
- *n = TotalMin(leftTop, middle, rightBottom, *n); // poisk summy znacheniy
- }
- // delete arr[i];
- }
- }
- if (key==2) {
- cout<<"Total min(chisla usliviya 'i-1>i<i+1') "<<*n<<endl;
- }
- if (key==3) {
- cout<<"Total mines(chisla otritsatelnye) "<<mines<<endl;
- }
- if (key==4) {
- delete n;
- //<udalit pamayt>
- for (int i = 0; i < nrow; i++) {
- delete [] a[i];
- }
- delete [] a;
- //</udalit pamayt>
- }
- if (key==6) {
- //<udalit pamayt>
- for (int i = 0; i < nrow; i++) {
- delete [] a[i];
- }
- delete [] a;
- //</udalit pamayt>
- return 0;
- }
- goto tryAgain;
- }
Add Comment
Please, Sign In to add comment