Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int *mas = new int[100];
- int max_1;
- int f(){
- return rand() % 100;
- }
- bool des(int a, int b){
- return a >= b;
- }
- int zero(){
- return 0;
- }
- int c(int b){
- mas[b] += 1;
- return 0;
- }
- void w(int a){
- cout << a << ' ';
- }
- bool more(int a, int b){
- return b <= a;
- }
- void repeat(int a){
- if (mas[a] == max_1){
- cout << a << ' ';
- mas[a] = -1;
- }
- }
- int main() {
- int n;
- cout << "n = ";
- cin >> n;
- vector <int> a(n);
- generate(a.begin(), a.end(), f);
- cout << "a = ";
- for_each(a.begin(), a.end(), w);
- cout << '\n';
- sort(a.begin(), a.end());
- reverse(a.begin(), a.end());
- cout << "sort a = ";
- for_each(a.begin(), a.end(), w);
- cout << '\n';
- a.push_back(rand() % 100);
- cout << "sort + rand a = ";
- for_each(a.begin(), a.end(), w);
- cout << '\n';
- generate(mas, mas + 100, zero);
- if (is_sorted(a.begin(), a.end(), des)){
- cout << "YES" << endl;
- }
- else{
- cout << "NO" << endl;
- }
- for_each(a.begin(), a.end(), c);
- max_1 = *(max_element(mas, mas + 100));
- cout << "max_repeat = ";
- for_each(a.begin(), a.end(), repeat);
- cout << '\n';
- make_heap(a.begin(), a.end(), more);
- cout << "make_heap = ";
- for_each(a.begin(), a.end(), w);
- cout << '\n';
- pop_heap(a.begin(), a.end());
- a.pop_back();
- cout << "pop_heap = ";
- for_each(a.begin(), a.end(), w);
- cout << '\n';
- cout <<"max_elem = "<< *(max_element(a.begin(), a.end())) << '\n';
- cout <<"min_elem = "<< *(min_element(a.begin(), a.end())) << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement