找出具有m行n列二维数组Array的“鞍点”,即该位置上的元素在该行上最大,在该列上最小,其中1<=m,n<=10。
找出具有m行n列二维数组Array的“鞍点”,即该位置上的元素在该行上最大,在该列上最小,其中1<=m,n<=10。
输入数据有多行,第一行有两个数m和n,下面有m行,每行有n个数。
按下列格式输出鞍点: Array[i][j]=x 其中x代表鞍点,i和j为鞍点所在的数组行和列下标,我们规定数组下标从0开始。 一个二维数组并不一定存在鞍点,此时请输出None。 我们保证不会出现两个鞍点的情况,比如:
3 3
1 2 3
1 2 3
3 6 8
3 3
1 2 3
4 5 6
7 8 9
Array[0][2]=3
代码
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
int main()
{
int x,y,i,j,m,p,x1,y1;
bool g;
cin>>x>>y;
int a[x][y];
for(i=0; i<x; ++i)
for(j=0; j<y; ++j)
{
cin>>a[i][j];
}
for(i=0; i<x; i++)
{
m=0;
for(j=0; j<y; ++j)
{
if(a[i][j]>m)
{
m=a[i][j];
x1=i;
y1=j;
}
}
g=true;
for(p=0;p<y;++p)
{
if(a[p][y1]<m)
g=false;
}
if(g)
cout<<"Array["<<x1<<"]["<<y1<<"]="<<m;
}
return 0;
}
原文地址:http://blog.csdn.net/blue_skyrim/article/details/46670983