Home > Back-end >  Run on vscode normal but displayed on the pta period of cuo 'wu
Run on vscode normal but displayed on the pta period of cuo 'wu

Time:11-11

Topic: a matrix elements of the "saddle point" refers to the position of the element value in the bank, the largest in the column, the smallest

Subject to code program, for a given n order square saddle points,

Input format:
Enter the first line is given a positive integer n (1 n 6 or less) or less, then n lines, each line is given n integers, separated by Spaces,

The output format:
Output in one line in accordance with the "row subscript column subscript" (subscript starting from 0) the format of the output of the saddle point position, if the saddle point does not exist, then output "NONE", the subject to ensure that the given matrix is a saddle point,

My code:
#include
using namespace std;
Int main () {
int n;
Cin> n;
Int Max [n].//the maximum array
Int min [n].//the minimum array
Int a [n] [n].//definition of two-dimensional array
If (n>=1 & amp; & N<{
=6)Int c=0;//determine parameter
int i;//counter
int j;//counter
Int u;//break parameter
int x,y;//a two-dimensional array of horizontal ordinate
Char b=' ';//space
for(i=0; ifor(j=0; JCin> A, [I] [j].
}
}//input matrix

for(i=0; iMax=[I] a [I] [0];
for(j=0; JIf (Max [I] <=a [I] [j]) {
Max=[I] a [I] [j];
}
}
}//Max array to find all the maximum
for(j=0; JMin [j] a [0]=[j];
for(i=0; iIf (min [j] & gt;=a [I] [j]) {
Min [j]=[I] a [j];
}
}
}//minimum array find columns minimum
for(i=0; ifor(j=0; JIf (Max==[I] a [I] [j]) {
X=j;
}
If (a [I] [x]==min [x]) {
Y=I;
C=1;
U=1;
break;
}

}
If (u==1) {
break;
}
}
If (c==1) {
Cout}
The else {
Cout<& lt;" NONE "& lt; }

}


return 0;
}

Vscode can be found in normal saddle points, but showing error on the pta
Also defined in the global arrays are less, the two layers of most nested loops stack capacity should be enough,

CodePudding user response:

 int n * Max, min, * * a; 
Cin> n;

If (n & lt; 1 | | n & gt; 6) {
Cout<& lt;" Input error!" return -1;
}
Max=new int [n].
Min=new int [n].

A=new int * [n].
For (int I=0; I & lt; n; I++)
A [I]=new int [n].

For (int I=0; I & lt; n; I++)
for (int j=0; J & lt; n; J++)
Cin> A, [I] [j].


Using dynamic array

The method of checking saddle points:

 void check_saddle_point (int (* point) [2], int (* array) [COL], int row, int COL) 
{
Int I, j, k, CNT=0;
Int row_idx col_idx;
Int max_row min_col;

For (I=0; I & lt; The row. I++) {
Max_row=array [0] [I];
Col_idx=0;
/* find value in a row */Max
For (j=1; J & lt; COL. J++)
If (max_row & lt; Array [I] [j]) {
Max_row=array [I] [j];
Col_idx=j;
}

/* Find value in col */min
Min_col=array [I] [col_idx];
Row_idx=I;
For (k=0; K & lt; The row. K++)
If (min_col & gt; Array [k] [col_idx]) {
Min_col=array [k] [col_idx];
Row_idx=k;
}
/* Check the condition */
If (row_idx==I & amp; & Min_col=={max_row)
Point (CNT) [0]=row_idx;
Point (CNT) [1]=col_idx;
Cnt++;
}

}
}

CodePudding user response:

Can you give me a check saddle points using dynamic array full code please let me run, is not very understanding
  • Related