nth_element函數


使用方法:nth_element(start, start+n, end)

使第n大元素處於第n位置(從0開始,其位置是下標為n的元素),並且比這個元素小的元素都排在這個元素之前,比這個元素大的元素都排在這個元素之后,但不能保證他們是有序的。

代碼:

 1 #include <algorithm>
 2 #include <iostream>
 3 #include <cstring>
 4 #include <cstdio>
 5  using  namespace std;
 6  const  int N= 101;
 7  char s[N];
 8  int main()
 9 {
10      int len,n;
11     gets(s);
12     len=strlen(s);
13     scanf( " %d ",&n);
14     nth_element(s,s+n,s+len);
15     puts(s);
16      return  0;
17 }

發現自己好像越來越懶了,懶得寫博客,老是積累好長時間的東西,哪天不想做題了一塊補上,總感覺這點東西沒必要寫。其實寫寫還挺好的,或許別人看到還可以給找出點錯誤。

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM