您的位置:首页 > 其它

一些项目——鞍点计算

2015-06-28 13:34 225 查看


Description

找出具有m行n列二维数组Array的“鞍点”,即该位置上的元素在该行上最大,在该列上最小,其中1<=m,n<=10。


Input

输入数据有多行,第一行有两个数m和n,下面有m行,每行有n个数。


Output

按下列格式输出鞍点: Array[i][j]=x 其中x代表鞍点,i和j为鞍点所在的数组行和列下标,我们规定数组下标从0开始。 一个二维数组并不一定存在鞍点,此时请输出None。 我们保证不会出现两个鞍点的情况,比如:

3 3

1 2 3

1 2 3

3 6 8


Sample Input

3 3
1 2 3
4 5 6
7 8 9


Sample Output

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: