[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
<1>题目描述
找一个二维数组中的鞍点,即该位置上的元素在该行上最大、在该列上最小。也可能没有鞍点
1 2 3 4 5 6 7 8 9 //3为该二维数组中鞍点
<2>思路分析
* 先找到第一行中最大的那个数a
* 将a与所在的列上其他数字进行比较,如果是最小,则输出a
* 如果a不是所在列最小的数,则找第二行最小的那个数b,重复第二步,直到找到鞍点
* 如果每一行中最大数都不是鞍点,则数组无鞍点
<3>代码实现
#include <stdio.h> #define ROW 3 //宏定义行 #define COL 3 //宏定义列 int main() { int
a[ROW][COL] = { {2,2,1},{4,5,6},{1,7,9} }; int k = 0; int j = 0; int i = 0; int
m = 0; for (i=0;i<ROW;i++) { int max = a[i][j]; //找第一行中最大的数字a for (j = 0; j <
COL; j++) { if (a[i][j] > max) { max = a[i][j]; //第二层循环走完以后,该max一定是该行中最大的那个数字 m
= j; //记录最大数字所在的列 } } j = 0; //判断a是否为所在列中最小的数 for (k = 0; k < ROW; k++) { if
(max > a[k][m]) { break; } } if (k == ROW) //表明a是该列中最小的数 { printf("鞍点为a[%d][%d]
= %d", i, m, max); break; } else k = 0; } if (i == ROW) printf("该二维数组没有鞍点\n");
return 0; }
<4>结果展示