Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <ctime>
- #include <iostream>
- #include <vector>
- using std::cin;
- using std::cout;
- using std::max;
- using std::min;
- using std::string;
- using std::vector;
- vector<int> F(vector<int> aa) {
- int nn = aa.size();
- if (nn <= 1) {
- return aa;
- }
- int pivid = rand() % nn;
- int piv = aa[pivid];
- vector<int> bb;
- vector<int> cc;
- for (int ii = 0; ii < nn; ++ii) {
- if (aa[ii] >= piv) {
- cc.push_back(aa[ii]);
- } else {
- bb.push_back(aa[ii]);
- }
- }
- bb = F(bb);
- cc = F(cc);
- vector<int> dd;
- for (int ii : bb) {
- dd.push_back(ii);
- }
- for (int ii : cc) {
- dd.push_back(ii);
- }
- return dd;
- }
- int main() {
- /*std::ios::sync_with_stdio(false);
- std::cin.tie(0);
- std::cout.tie(0);*/
- int nn;
- cin >> nn;
- vector<int> aa(nn);
- for (int& ii : aa) {
- cin >> ii;
- }
- aa = F(aa);
- for (int ii : aa) {
- cout << ii << ' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement