Exercises 7-5 find saddle points (20 points)

A "saddle point" refers to the maximum matrix element value of the element at that position, the minimum on the column on the line.

This problem requires programming, seeking a given n-order square matrix saddle point.

Input formats:

The first input line is given a positive integer n (1≤n≤6). Then n lines of n integers are given, separated by a space therebetween.

Output formats:

Output in "lower line marked column index" (index starting from 0) of the output format saddle point position in a row. If the saddle point does not exist, the output "NONE". Title ensure a given matrix at most one saddle point.

Sample Input 1:

4
1 7 4 1
4 8 3 6
1 6 1 2
0 7 8 9

 

Output Sample 1:

2 1

 

Sample Input 2:

2
1 7
4 1

 

Output Sample 2:

NONE

answer:

#include<stdio.h>
int main(){
    int n,max,min,a[10][10];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        max=a[i][0];
        for(int j =0;j<n;j++){
            scanf("%d",&a[i][j]);
            if(a[i][j]>max){
                max = a[i][j];
                a[i][9] = max;
            }
        }
    }
    for(int j=0;j<n;j++){
        min=a[0][j];
        for(int i = 0;i<n;i++){
            if(a[i][j]<min){
                min = a[i][j];
                a[9][j] = min;
            }
        }
    }
    int flag=0;
    for(int i = 0;i<n;i++){
        for(int j = 0;j<n;j++){
            if(a[i][9]==a[9][j]){
                printf("%d %d",i,j);
                flag=1;
            }
        }
    }
    if(flag==0) printf("NONE");
    return 0;
}

Always make life difficult for a test point. .

 

Published 98 original articles · won praise 2 · Views 3719

Guess you like

Origin blog.csdn.net/qq_30377869/article/details/104806743