StoneHaos

misha2

Oct 17th, 2020
497
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <set>
  3. #include <string>
  4. #include <stdlib.h>
  5. #include <time.h>
  6. #include <algorithm>
  7.  
  8. using namespace std;
  9.  
  10. void print(set<double> s) {
  11.     for (auto iter = s.begin(); iter != s.end(); ++ iter)
  12.         cout << *iter << " ";
  13.     cout << endl;
  14. }
  15.  
  16. int main(void) {
  17.     srand(time(NULL));
  18.  
  19.     int n;
  20.     cout << "Input length: ";
  21.     cin >> n;
  22.  
  23.     set<double> s, s_;
  24.     for (int i = 0; i < n; ++ i)
  25.         s.insert(rand() % 100);
  26.  
  27.     print(s);
  28.     cout << "MAX: " << *(--s.end()) << endl;
  29.  
  30.     int a, b;
  31.     cout << "Diapazon: ";
  32.     cin >> a >> b;
  33.     if (a > b) swap(a, b);
  34.     s.erase(s.lower_bound(a), s.upper_bound(b));
  35.     print(s);
  36.  
  37.     double sum = 0;
  38.     for (auto iter = s.begin(); iter != s.end(); ++ iter)
  39.         sum += *iter;
  40.     sum /= s.size();
  41.     cout << "Srznach: " << sum << endl;
  42.     s_ = s;
  43.     s.clear();
  44.     for (auto iter = s_.begin(); iter != s_.end(); ++ iter)
  45.         s.insert(*iter + sum);
  46.     print(s);
  47.     return 0;
  48. }
RAW Paste Data