• 习题7-5 找鞍点


     1 #include<stdio.h>
     2 
     3 int main(void)
     4 {
     5     int n;
     6     int a[6][6];
     7     int row_max[6];        //每 一行的最大数
     8     int col_min[6];        //每一列的最大数
     9 
    10     scanf_s("%d", &n);
    11 
    12     for (int i = 0; i < n; i++)
    13     {
    14         for (int j = 0; j < n; j++)
    15         {
    16             scanf_s("%d", &a[i][j]);
    17         }
    18     }
    19 
    20     /*找出每一行的最大值*/
    21     for (int i = 0; i < n; i++)
    22     {
    23         int row_max_index = 0;
    24         for (int j = 1; j < n; j++)
    25         {
    26             if (a[i][row_max_index] < a[i][j])
    27             {
    28                 row_max_index = j;
    29             }
    30         }
    31 
    32         row_max[i] = a[i][row_max_index];
    33     }
    34 
    35     /*找出每一列的最小值*/
    36     for (int i = 0; i < n; i++)
    37     {
    38         int col_min_index = 0;
    39         for (int j = 1; j < n; j++)
    40         {
    41             if (a[j][i] < a[col_min_index][i])
    42             {
    43                 col_min_index = j;
    44             }
    45         }
    46 
    47         col_min[i] = a[col_min_index][i];
    48     }
    49 
    50     int count = 0;        //统计鞍点的个数
    51     for (int i = 0; i < n; i++)
    52     {
    53         for (int j = 0; j < n; j++)
    54         {
    55             if (a[i][j]==row_max[i]&&a[i][j]==col_min[j])
    56             {
    57                 printf("%d %d
    ", i, j);
    58                 count++;
    59             }
    60         }
    61     }
    62 
    63     if (count == 0)
    64     {
    65         printf("NONE
    ");
    66     }
    67 
    68     return 0;
    69 }
  • 相关阅读:
    javascript 数字格式化
    spring-cloud blogs
    rabbitmq python
    centos7下 安装mysql
    hue install
    d3 document
    elastichq 离线安装
    elasticsearch agg
    elastichq auto connect
    Go Hello World!
  • 原文地址:https://www.cnblogs.com/2018jason/p/12009039.html
Copyright © 2020-2023  润新知