1. 程式人生 > >之前鞍點代碼的bug補充

之前鞍點代碼的bug補充

str 分別是 i++ ostream end mes namespace g++ rar

#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 << "請輸入二維數組的行數:\n" ;
cin >> m;
cout << "請輸入二維數組的行數:\n"; // 1 1 1 1 2
cin >> n;
cout <<"請輸入矩陣:\n";
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] <<"\t";
cout <<"\n";
}

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 << "鞍點坐標和值分別是:\n";
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 <<"沒有鞍點!\n" << endl;
return 0;
}

之前鞍點代碼的bug補充