之前鞍点代码的bug补充
Posted cstdio1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了之前鞍点代码的bug补充相关的知识,希望对你有一定的参考价值。
#include <iostream>
using namespace std;
int main()
{
const int a = 15,b = 15;
int m, n, i, j, max_num[50], min_num[50], flag = 0,x ,y;
int arrary[a][b], hang[a][b] = {-999}, lie[a][b] = {-999},count=0;
//cout << "Hello world!" << endl;
cout << "请输入二维数组的行数:
" ;
cin >> m;
cout << "请输入二维数组的行数:
"; // 1 1 1 1 2
cin >> n;
cout <<"请输入矩阵:
";
for(i = 0;i < m;i++)
{
for(j = 0;j < n;j++)
cin >> arrary[i][j];
}
for( i = 0;i < m;i++)
{
max_num[i] = arrary[i][0];
for(j = 0;j < n;j++)
{
if(max_num[i] == arrary[i][j])
{
max_num[i] = arrary[i][j];
hang[i][j] = arrary[i][j];
x = i; y = j;
}
if(max_num[i] > arrary[i][j])
hang[i][j] = -999;
if(max_num[i]< arrary[i][j])
{
hang[x][y] = -999;
max_num[i] = arrary[i][j];
x = i; y = j;
hang[i][j] = arrary[i][j];
}
}
}
for(i = 0;i < m;i++)
{
for(j = 0;j <n;j++)
{
if(hang[i][j] != max_num[i]) hang[i][j] =-999;
}
}
/*
for(i = 0;i < m;i++)
{
for(j = 0;j < n;j++)
cout <<hang[i][j] <<" ";
cout <<"
";
}
return 0;*/
for(j = 0;j < n;j++)
{
min_num [j]= arrary[0][j];
for(i = 0;i < m;i++)
{
if(min_num[j] == arrary[i][j] )
{
min_num[j]= arrary[i][j];
x = i; y = j;
lie[i][j] = arrary[i][j];
}
if(min_num[j] < arrary[i][j])
lie[i][j] = -999;
if(min_num[j] > arrary[i][j])
{
lie[x][y] = -999;
min_num[j] = arrary[i][j];
x = i; y = j;
lie[i][j] = arrary[i][j];
}
}
}
for(i = 0;i < m;i++)
{
for(j = 0;j <n;j++)
{
if(lie[i][j] != min_num[j]) lie[i][j] =-999;
}
}
//cout << "鞍点坐标和值分别是:
";
for(i = 0;i < m;i++)
{
for(j = 0;j < n;j++)
if(hang[i][j] == lie[i][j] && hang[i][j] != -999)
{
flag++;
cout << "第" << i+1 <<"行" << "第" << j+1 <<"列:" << lie[i][j] << endl;
}
}
if(!flag) cout <<"没有鞍点!
" << endl;
return 0;
}
以上是关于之前鞍点代码的bug补充的主要内容,如果未能解决你的问题,请参考以下文章