📄 lab3.cpp
字号:
#include <iostream>
#define MAX 10
using namespace std;
int main() {
int array[MAX][MAX];//array to store the matrix
int size; //size of the array
int rowMaxValue; //use to store the local max value
int colMinValue[MAX]; //use to store the local min val.
int rowMax[MAX]; //use to store the pos of max.
int colMin[MAX]; //use to store the pos of min.
int i;
int j;
srand(time(0)); //initialize
cout << "input the size length of the array :\n";
cin >> size;
//construct the array to store the matrix
cout << "The size of the array is [ " << size << " ]\n";
for(i = 0; i < size; i++) {
for(j = 0; j < size; j++) {
array[i][j] = rand() % 100;
cout << array[i][j] << "\t";
}
cout << "\n";
rowMax[i] = 0;
colMin[i] = 100;
colMinValue[i] = 100;
}
//scan the matrix to find the local maxs and mins
for(i = 0; i < size; i++) { //row i
rowMaxValue = 0;
for(j = 0; j < size; j++) { //col j
if(rowMaxValue < array[i][j]) {
rowMaxValue = array[i][j];
rowMax[i] = j;
}
if(colMinValue[j] > array[i][j]) {
colMinValue[j] = array[i][j];
colMin[j] = i;
}
}
}
//search for the required point.
for(i = 0; i < size; i++) {
if(colMin[rowMax[i]] == i) {
cout << "Found, The point is " << array[i][rowMax[i]] << ",\nat row " << i << " and column " << rowMax[i] << "\n";
return 1;//found
}
}
cout << "Not Found!";//not found
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -