标签:并且 include i++ pos pen name namespace lag not found
给定一个5*5的矩阵,每行只有一个最大值,每列只有一个最小值,寻找这个矩阵的鞍点。
鞍点指的是矩阵中的一个元素,它是所在行的最大值,并且是所在列的最小值。
例如:在下面的例子中(第4行第1列的元素就是鞍点,值为8 )。
11 3 5 6 9
12 4 7 8 10
10 5 6 9 11
8 6 4 7 2
15 10 11 20 25
如果存在鞍点,输出鞍点所在的行、列及其值,如果不存在,输出"not found"
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
using namespace std;
int num[5][5];
int r[5];
int main()
{
memset(num,0,sizeof(num));
for(int i=0;i<5;i++)
for(int j=0;j<5;j++)
cin>>num[i][j];
bool flag=true;
for(int i=0;i<5;i++)
{
int mnum=99999;
int ipos= max_element(num[i],num[i]+5)-num[i];
r[i]=num[i][ipos];
for(int j=0;j<5;j++)
mnum=mnum<num[j][ipos]?mnum:num[j][ipos];
if(mnum==r[i])
{flag=false;
cout<<i+1<<" "<<ipos+1<<" "<<mnum<<endl;
}
}
if(flag)
cout<<"not found"<<endl;
}
标签:并且 include i++ pos pen name namespace lag not found
原文地址:http://www.cnblogs.com/masterchd/p/6727260.html