P1138 第k小整数(洛谷)

题目描述:

  传送门

题解:一道入门的桶排序,过于简单所以直接贴代码

代码:

 1 #include<iostream>
 2 using namespace std;
 3 
 4 int count[30000]={0};
 5 int main(){
 6     int a[10000];
 7     int n,k;
 8     cin>>n>>k;
 9     for(int i=0;i<n;i++){
10         cin>>a[i];
11         count[a[i]]++;
12     }
13     
14     int time=0;
15     for(int i=0;i<30000;i++){
16         if(count[i]!=0)    time++;
17         if(time==k){
18             cout<<i;
19             return 0;
20         }
21     }
22     cout<<"NO RESULT";
23     return 0;
24 }

 

posted @ 2020-05-01 23:19  neverstopcoding  阅读(209)  评论(0编辑  收藏  举报