Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <deque>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. int mx;
  7.  
  8. // проверяет, равен ли х максимуму
  9. bool ismax(int x) {
  10.     return x == mx;
  11. }
  12.  
  13. // проверяет, является ли четным
  14. bool iseven(int x) {
  15.     return x % 2 == 0;
  16. }
  17. int main() {
  18.     // считываем количество элементов в последовательности
  19.     int n;
  20.     cin >> n;
  21.  
  22.     deque<int> d;
  23.  
  24.     for (int i = 0; i < n; ++i) {
  25.         int x;
  26.         cin >> x;
  27.         d.push_back(x);
  28.     }
  29.  
  30.     // удаление элементов равных максимальному
  31.     mx = *max_element(d.begin(), d.end());
  32.     d.erase(remove_if(d.begin(), d.end(), ismax), d.end());
  33.     cout << "Sequence after removing maximum elements:" << endl;
  34.     for (auto it = d.begin(); it != d.end(); ++it) {
  35.         cout << *it << " ";
  36.     }
  37.     cout << endl;
  38.  
  39.     // сортировка
  40.     sort(d.begin(), d.end());
  41.     cout << "Sorted sequence:" << endl;
  42.     for (auto it = d.begin(); it != d.end(); ++it) {
  43.         cout << *it << " ";
  44.     }
  45.     cout << endl;
  46.  
  47.     // удаление повторяющихся элементов
  48.     d.erase(unique(d.begin(), d.end()), d.end());
  49.     cout << "Sequence after removing repeating elements:" << endl;
  50.     for (auto it = d.begin(); it != d.end(); ++it) {
  51.         cout << *it << " ";
  52.     }
  53.     cout << endl;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement