Home > Back-end >  C: spell a time after submission
C: spell a time after submission

Time:09-29

Topic 7-5 for a two-dimensional array of saddle points (25 points)
For two-dimensional array arr [5] [4] in the saddle point and a saddle point is the index set of arr arr [I] [j] element value in the first line I minimum, and maximum in the first column j, try to write a program to find all the saddle point in the array arr, and the output values underneath, and if there is no saddle points, print the Not Found,

Input format:
Input 5 lines four columns of two-dimensional arrays,

The output format:
All the saddle point in the output of the two dimensional array, and the output value of the corresponding row subscript and column in the table below, if you don't find a saddle point, output is Not Found,

Input the sample:
20 15 43 75
165 183 88 95
6 0 to 5 7
35 8 September 16
10 July 15 33



The output sample:
88 [1, 2]



Input the sample:
1 2 3 4
5 6 7 8
9 10 11 17
13 14 15 16
20 18 19 12



The output sample:
Not Found



Principle of feeling about the same, why is my show time? Please bosses guidance,

CodePudding user response:

Hair so many pictures, as the code directly to the posted ~

 # include & lt; stdio.h> 
#include
#include

# define ROW 4
# define COL 5


Void init_array (int (* array) [COL], int row, int COL)
{
Int I, j;

Srand (time (NULL));
For (I=0; i For (j=0; J & lt; Col. J++)
Array [I] [j]=rand () % 100;
}


Void show_array (int (* array) [COL], int row, int COL)
{
Int I, j;

For (I=0; i For (j=0; J & lt; Col. J++)
Printf (" % 2 d ", array [I] [j]);
Putchar (10);
}
}

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 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++;
}

}
}

Void init_point_array (int (* point) [2], int row)
{
Int I, j;

For (I=0; i For (j=0; J & lt; 2; J++)
Point [I] [j]=1;
}

Void show_saddle_point (int (* point) [2], int (* array) [COL], int row)
{
Int I, row_idx col_idx;

For (I=0; i Row_idx=point [I] [0];
Col_idx=point [I] [1];
If (row_idx & gt;=0 & amp; & Col_idx & gt;=0)
Printf (" saddle points for array [% d] [% d]=% d \ n ", row_idx, col_idx, array [row_idx] [col_idx]);
}
}

Int main (void)
{
An int array [ROW] [COL];
Int point [ROW] [2];

Init_array (array, the ROW, COL);
Init_point_array (point, ROW);
Show_array (array, the ROW, COL);
Check_saddle_point (point, array, the ROW, COL);
Show_saddle_point (point, array, ROW);

return 0;
}

For your reference ~
Prev:ASP.NET
Next:python
  • Related