Init
This commit is contained in:
16
ACMOJ-1040.cpp
Normal file
16
ACMOJ-1040.cpp
Normal file
@ -0,0 +1,16 @@
|
||||
#include <iostream>
|
||||
#include "ACMOJ-1040.hpp"
|
||||
|
||||
int a[9] = {1, 5, 6, 2, 7, 3, 9, 4, 8};
|
||||
|
||||
bool cmp(const int &x, const int &y){return x > y;}
|
||||
|
||||
int main()
|
||||
{
|
||||
nth_element(a, a + 8, a + 9, cmp);//find the 8th(0-base) greatest value in a with cmp as comparator
|
||||
std::cout << *(a + 5) << std::endl;// 4
|
||||
sort(a, a + 9, [](const int &x, const int &y){return x < y;});//comp is a lambda expression, which returns true if and only if x < y
|
||||
for (int i = 0;i < 9;++ i) std::cout << a[i] << " ";// 1 2 3 4 5 6 7 8 9
|
||||
std::cout << std::endl;
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user