Finding the "saddle point" of a two-dimensional array

Source: Internet
Author: User

Saddle point: The element on the position is the largest on the row, the smallest on the column. There may also be no saddle points.

1#include <stdio.h>2#include <stdlib.h>3 #defineN 44 #defineM 55 intMain ()6 {7     intI,j,k,maxj,max,a[n][m],flag;8printf"input matrix:\n");9      for(i=0; i<n;i++){Ten          for(j=0; j<m;j++){ Onescanf"%d",&a[i][j]); A         } -     } -      for(i=0; i<n;i++){ the          for(j=0; j<m;j++){ -printf"%5d", A[i][j]); -         } -printf"\ n"); +     } -      for(i=0; i<n;i++){ +max=a[i][0];//start assuming a[i][0] Max Amaxj=0;//The column number of the maximum number exists in the MAXJ at          for(j=0; j<m;j++) {//Find the maximum row value -             if(a[i][j]>max) { -max=A[i][j]; -Maxj=j;//The column number of the maximum number exists in the MAXJ -             } -         } inflag=1;//assumed to be a saddle point -          for(k=0; k<n;k++){ to             if(Max > A[K][MAXJ]) {//Compare the maximum number of rows to the same column element +flag=0;//If the number is not the smallest of the same column, the representation is not the saddle point, making flag=0; -                 Continue;//jump out of the K loop the             } *         } $         if(flag) {//A flag of 1 means a saddle point.Panax Notoginsengprintf"a[%d][%d]=%d\n", I,maxj,max); -              Break;//jump out of I loop the         } +     } A     if(!flag) theprintf"Not exist\n"); +System"Pause"); -     return 0; $}

Finding the "saddle point" of a two-dimensional array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.