Find the first minimum number and the second one.
来源:互联网 发布:王珊数据库视频教程 编辑:程序博客网 时间:2024/05/18 04:15
在一个数组中找出最小的两个数,复杂度为O(n);
#include "stdafx.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <time.h>int a[10000000];int main() { srand(time(NULL)); int i; for (i = 0; i < 10000; i++) a[i] = rand(); long start = clock(); int min1 = a[0], min2 = a[0]; for (i = 0; i < sizeof(a) / sizeof(a[0]); i++) { if (a[i] < min1){ min2 = min1; min1 = a[i]; } } printf ("%d\n%d", min1, min2); printf ("\nTime is %d ms", clock() - start); putchar ('\n'); system ("pause"); return 0;}
阅读全文
0 0
- Find the first minimum number and the second one.
- The Second One
- Choose the second one
- Get a first life in the second one
- hdu 3752 Is the one been second-killed first?
- [3752]:Is the one been second-killed first?
- The first and second conditional to ask and answer questions
- The First One
- the first one
- The first one
- The First One
- The first one
- the first one
- The first one.
- the first one.
- 1435: Find the minimum
- Find the kth minimum.
- 杭电ACM HDU 3752 Is the one been second-killed first?
- POJ
- Excel VBA高效办公应用-第二章-Excel VBA编辑基础-Part4(VBA控制语句)
- 6.Nginx 的 Rewrite 规则
- CodeForces 814A An abandoned sentiment from past
- 项目jdk/jar包冲突分析处理过程
- Find the first minimum number and the second one.
- JS内存泄漏排查方法(Chrome Profiles)
- JVM编译优化
- android布局优化之<include>标签的使用
- 串口通讯项目
- 欢迎使用CSDN-markdown编辑器
- Spark中External Datasource实现数据迁移
- CodeForces 814B An express train to reveries
- linux Xinetd服务简介