首页 > 其他 > 详细

习题7-5 找鞍点

时间:2019-12-09 10:04:37      阅读:193      评论:0      收藏:0      [点我收藏+]

技术分享图片

 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\n", i, j);
58                 count++;
59             }
60         }
61     }
62 
63     if (count == 0)
64     {
65         printf("NONE\n");
66     }
67 
68     return 0;
69 }

 

习题7-5 找鞍点

原文:https://www.cnblogs.com/2018jason/p/12009039.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!