Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by 666 ( 15 years ago )
#include <iostream>
 #include <iomanip>
 #include <cstdio>
 #include <cmath>

 using namespace std;

 void Local_Minimum(int **a,const int m,const int n);

 bool isLocalMinimum(int **a, int i, int j,const int m,const int n);

 int main()
 { 
 const int m=3,n=3;
 int **a=new int *[m];
 cout<<("input Massive,but he is BIG\n");
 for(int i=0;i<m;i++) a[i]=new int [n];
 for(i=0;i<m;i++)
 for(int j=0;j<n;j++)cin>>a[i][j];
 for(i=0;i<m;i++){for(int j=0;j<n;j++)cout<<setw(10)<<a[i][j]<<' ';cout<<endl;}
 Local_Minimum(a,m,n);
 return 0;
 }


 bool isLocalMinimum(int **a, int i, int j,const int m,const int n)
 {
 int value=a[i][j];
 /* int value=a[i][j];
 /*Проверка границы, затем проверка соседа*/
 if(i>0 && value>a[i-1][j] ) return false;
 if(j>0 && value>a[i] [j-1]) return false;
 if(i<m && value>a[i+1][j] ) return false;
 if(j<n && value>a[i] [j+1]) return false;

 }

 void Local_Minimum(int **a,const int m,const int n)
 {
 int count=0;
 for(int i=0;i<=m;i++)
 for(int j=0;j<=n;j++)
 if(isLocalMinimum(a, i, j, m, n))
 {
 cout<<"Local minimum "<<" at ("<<i<<","<<j<<")"<<endl;
 count++;
 }
 cout<<"There are "<<count<<" local minimas in the matrix"<<endl;
 }

 

Revise this Paste

Your Name: Code Language: