九度OJ-题目1174:查找第K小数-10网研上机B
来源:互联网 发布:社交网络 百度云盘 编辑:程序博客网 时间:2024/06/06 15:48
题目描述:
查找一个数组的第K小的数,注意同样大小算一样大。
如 2 1 3 4 5 2 第三小数为3。
输入:
输入有多组数据。
每组输入n,然后输入n个整数(1<=n<=1000),再输入k。
输出:
输出第k小的整数。
样例输入:
6
2 1 3 5 2 2
3
样例输出:
3
#include <iostream>#include <cstdio> #include <algorithm>#define MAXSIZE 1010using namespace std;int main(){ int n,k; int count,min; int buf[MAXSIZE]; while (scanf("%d",&n)!=EOF){ //input for (int i=0;i<n;i++){ scanf("%d",&buf[i]); } scanf("%d",&k); //sort sort(buf,buf+n); //search count=1; min=buf[0]; for (int i=1;i<n;i++){ if (buf[i]>min){ min=buf[i]; count++; } if (count==k){ printf("%d\n",buf[i]); break; } } } return true;}
0 0
- 九度OJ-题目1174:查找第K小数-10网研上机B
- 九度OJ 题目1174:查找第K小数
- 九度oj 题目1174:查找第K小数(sort的使用)
- 【九度OJ】题目1174:查找第K小数 解题报告
- 九度OJ 1174 查找第K小数 (STL)
- 九度OJ 1174:查找第K小数 (排序、查找)
- 九度OJ-题目1173:查找-10网研上机A
- 九度OJ-题目1176:树查找-10网研上机D
- 题目1174:查找第K小数
- 题目1174:查找第K小数
- 题目1174:查找第K小数
- 题目1174:查找第K小数
- 题目1174:查找第K小数
- 九度OJ-题目1170:找最小数-10计院上机B
- 九度OJ-题目1175:打牌-10网研上机C
- 题目1173:查找 九度OJ
- 九度OJ题目1173:查找
- 九度OJ题目1176:树查找
- 九度OJ-题目1173:查找-10网研上机A
- 《第一行代码》Android 学习笔记
- [BFS]poj 2251 Dungeon Master
- 基于UDP的select函数用法
- (LeetCode) 268. Missing Number
- 九度OJ-题目1174:查找第K小数-10网研上机B
- (LeetCode) 191. Number of 1 Bits
- L1-031. 到底是不是太胖了
- 博客
- Listener
- 170320 汇编-第四章-程序结构、debug跟踪,qt图片适应
- EventBus3的使用实战(一)
- 读书-元曲-《山坡羊-道情》
- 系统引导时为什么要关闭Catchs?