Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <iomanip>
- using namespace std;
- void printArr(vector<float> &x) {
- for (float i : x)
- cout << setprecision(2) << i << ' ';
- cout << '\n';
- }
- void sort_shit(vector<float> &x) {
- for (int i = 0; i < x.size(); i++) {
- if (abs(x[i]) < 1) {
- int j = i;
- while (x[j--] < 1) {
- swap(x[j], x[j+1]);
- if (j == 0 || abs(x[j-1]) < 1)
- break;
- }
- }
- }
- }
- int main() {
- int n;
- cin >> n;
- vector<float> v(n);
- for (int i = 0; i < n; i++) {
- v[i] = (float)rand() / RAND_MAX * 4 - 2;
- }
- printArr(v);
- sort_shit(v);
- printArr(v);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement