Advertisement
Guest User

Untitled

a guest
May 19th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. int *mas = new int[100];
  5. int max_1;
  6. int f(){
  7.     return rand() % 100;
  8. }
  9. bool des(int a, int b){
  10.     return a >= b;
  11. }
  12. int zero(){
  13.     return 0;
  14. }
  15. int c(int b){
  16.     mas[b] += 1;
  17.     return 0;
  18. }
  19. void w(int a){
  20.     cout << a << ' ';
  21. }
  22. bool more(int a, int b){
  23.     return b <= a;
  24. }
  25. void repeat(int a){
  26.     if (mas[a] == max_1){
  27.         cout << a << ' ';
  28.         mas[a] = -1;
  29.     }
  30. }
  31. int main() {
  32.     int n;
  33.     cout << "n = ";
  34.     cin >> n;
  35.     vector <int> a(n);
  36.     generate(a.begin(), a.end(), f);
  37.     cout << "a = ";
  38.     for_each(a.begin(), a.end(), w);
  39.     cout << '\n';
  40.     sort(a.begin(), a.end());
  41.     reverse(a.begin(), a.end());
  42.     cout << "sort a = ";
  43.     for_each(a.begin(), a.end(), w);
  44.     cout << '\n';
  45.     a.push_back(rand() % 100);
  46.     cout << "sort + rand a = ";
  47.     for_each(a.begin(), a.end(), w);
  48.     cout << '\n';
  49.     generate(mas, mas + 100, zero);
  50.     if (is_sorted(a.begin(), a.end(), des)){
  51.         cout << "YES" << endl;
  52.     }
  53.     else{
  54.         cout << "NO" << endl;
  55.     }
  56.     for_each(a.begin(), a.end(), c);
  57.     max_1 = *(max_element(mas, mas + 100));
  58.     cout << "max_repeat = ";
  59.     for_each(a.begin(), a.end(), repeat);
  60.     cout << '\n';
  61.     make_heap(a.begin(), a.end(), more);
  62.     cout << "make_heap = ";
  63.     for_each(a.begin(), a.end(), w);
  64.     cout << '\n';
  65.     pop_heap(a.begin(), a.end());
  66.     a.pop_back();
  67.     cout << "pop_heap = ";
  68.     for_each(a.begin(), a.end(), w);
  69.     cout << '\n';
  70.     cout <<"max_elem = "<< *(max_element(a.begin(), a.end())) << '\n';
  71.     cout <<"min_elem = "<< *(min_element(a.begin(), a.end())) << '\n';
  72.     return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement