Advertisement
Guest User

4

a guest
Jan 19th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     queue<int> q;
  9.     int x;
  10.     cin >> x;
  11.     q.push(x); // вводишь один элемент и сразу запихиваешь в кью
  12.     while(cin >> x){
  13.         if(x != q.back()){ // если новый элемент не равен последнему элементу в кью, запихиваешь его в кью
  14.             q.push(x);
  15.         }
  16.     }
  17.     int n = q.size();// запоминаешь размер кью
  18.     for(int i = 0; i < n; i++){//выводишь последовательность
  19.         cout << q.front() << ' ';
  20.         q.pop();
  21.     }
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement