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 }

发现自己好像越来越懒了,懒得写博客,老是积累好长时间的东西,哪天不想做题了一块补上,总感觉这点东西没必要写。其实写写还挺好的,或许别人看到还可以给找出点错误。

原文地址:https://www.cnblogs.com/pony1993/p/2671388.html