Created
December 23, 2015 08:15
-
-
Save lishunan246/7d39e261b09930076897 to your computer and use it in GitHub Desktop.
1045. 快速排序(25)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <iterator> | |
using namespace std; | |
int main() | |
{ | |
int N; | |
cin >> N; | |
vector<pair<long long, bool>> v; | |
for (auto i = 0; i < N; ++i) | |
{ | |
long long t; | |
cin >> t; | |
v.push_back({t,true}); | |
} | |
decltype(v) result; | |
auto max = (*v.cbegin()).first; | |
for (auto i = v.begin(); i != v.end(); ++i) | |
{ | |
if (i->first < max) | |
i->second = false; | |
else | |
max = i->first; | |
} | |
auto min = (*v.crbegin()).first; | |
for (auto i = v.rbegin(); i != v.rend(); ++i) | |
{ | |
if (i->first > min) | |
i->second = false; | |
else | |
min = i->first; | |
} | |
copy_if(v.cbegin(), v.cend(), back_inserter(result), [](const pair<long long, bool> p) | |
{ | |
return p.second; | |
}); | |
cout << result.size() << endl; | |
if (result.size()) | |
{ | |
auto t = result.begin(); | |
cout << t->first; | |
result.erase(t); | |
} | |
for_each(result.cbegin(), result.cend(), [](const pair<long long, bool> p) | |
{ | |
cout << " " << p.first; | |
}); | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment