求数组中的次大值
来源:互联网 发布:淘宝选品数据分析 编辑:程序博客网 时间:2024/06/05 11:21
#include <iostream>#include <time.h>#include <stdlib.h>using namespace std;int main(int argc, char** argv) {int s[10];srand((unsigned)time(NULL));for (int i = 0; i<10; i++){s[i] = rand() % 1000 + 1;}printf("随机生成的10个数为:");for (int i = 0; i<10; i++){printf("%d ", s[i]);}int one = 0, two = 0;if (s[0] >= s[1]){one = s[0];two = s[1];}else{one = s[1];two = s[0];}for (int i = 2; i<10; i++) //数组遍历一次{if (s[i]>one){two = one;one = s[i];}else{if (s[i]>two){two = s[i];}}}printf("\n最大:%d 第二大:%d", one, two);return 0;}
0 0
- 求数组中的次大值
- 求数组中的次大值
- 求一个数组中的最大和次大值
- 求数组中的最大值
- 求数组中的最大值
- 求给定数组中的最大值
- 求给定数组中的最大值
- 求数组中的最长平台
- 求数组中的逆序对
- 求二维数组中的最小值
- 求二维数组中的最大值
- 求数组中的重复值
- js 求数组中的最大值
- 求数组中的逆序对
- 求数组中的逆序对
- 求数组中的两个最大值
- 求数组中的逆序对
- 如何求数组中的最大值
- 自定义Veiw的实践(一)---一个简易侧滑菜单的实现
- hdu 2602 Bone Collector
- Codeforces 469D Two Sets【思维+并查集】
- PAT 1003 乙等 (我要通过) c++
- trunk函数详解
- 求数组中的次大值
- 数位DP-要49-基础DP-hdu3555-四种方法
- MyBatis架构设计及源代码分析(一):MyBatis架构
- 用node.js写的http小爬虫
- 1010: "水仙花数"问题1
- 菜鸟学习Spring——SpringMVC注解版控制层重定向到控制层
- PHP中include()与require()的区别
- Asp.Net Core 连接MySQL
- POJ 2313