Problem C: 查找【数组】
来源:互联网 发布:淘宝店铺会员管理 编辑:程序博客网 时间:2024/06/06 03:30
Problem C: 查找【数组】
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 220 Solved: 73
[Submit][Status][Web Board]
Description
利用search(a,n,k)函数在数组a的前n(n>=1)个元素中找出前k个(1<=k<=n)小的值。假设数组a中各元素的值都不相同。
Input
数组中各元素
n k
Output
a中前k个小的值
Sample Input
5 6 2 1 4 85 78 117 4
Sample Output
5 2 1 4
HINT
代码实现:
#include<iostream>#include<algorithm>using namespace std;void search(int a[1000],int n ,int k){ int b[1000]; int times=0; for(int i=0;i<n;i++) { b[i]=a[i]; } sort(a,a+n); for(int m=0;m<n;m++) { for(int j=0;j<k;j++) { if(a[j]==b[m]) { cout<<a[j]; times++; if(times!=k) { cout<<" "; } } } if(times==k) return ; }}int main(){ int one[1000]; int k=0; while(cin>>one[k]) { k++; } int m=one[k-2]; int n=one[k-1]; search(one,m,n); return 0;}
0 0
- Problem C: 查找【数组】
- oj Problem C: 查找【数组】
- oj 2325 Problem C 查找【数组】
- oj刷题 Problem C: 查找【数组】
- Problem E: 二维数组中的查找
- Problem C: 数组---求数组中的最大值
- Problem E: 数组---在数组中查找元素
- C语言数组折中查找
- 【C++】二维数组中的查找
- C#-数组的元素查找
- 二维数组查找算法(C++)
- C语言二分法查找数组
- C语言 有关数组查找
- Problem M 在数组中查找指定元素 函数
- Problem C: 数组类(I)
- Problem C: 数组类(I)
- Problem C: 数组类(I)
- C语言中的数组元素查找
- Problem B: 子序列问题(线性表)
- 使用类图表示你的设计模式——适配器模式!
- 异常聚合方法
- C语言基础 输出一维整型数组中的一个元素
- AndroidStudio ---设备OFFINE,在开发环境识别异常
- Problem C: 查找【数组】
- Problem D: C++习题-快速排序 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 395 Solved: 169 [Submit][Stat
- C语言基础 定义一维字符型数组并初始化
- 爆搜。。。。。。。
- Problem E: Satellite Photographs
- Windows CMD命令大全
- Java设计模式——装饰者模式
- jzoj 2016.6.25noip模拟赛C 总结
- 如何通过mybatis逆向工程生成实体类以及dao和mapper.xml