Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cassert>
- #include <queue>
- using namespace std;
- #define Type int
- int count (queue <Type> q)
- {
- int res = 0;
- Type n1 = q.front(); q.pop();
- while(!q.empty())
- {
- Type n2 = q.front(); q.pop();
- if (n1 == n2) ++res;
- n1 = n2;
- }
- return res;
- }
- void del (queue <Type> &q, int n)
- {
- Type n1 = q.front(); q.pop(); q.push(n1);
- for (int i = 1; i < n; ++i)
- {
- n1 = q.front(); q.pop();
- Type n2 = q.back();
- if (n1 != n2) q.push(n1);
- }
- }
- void print (queue <Type> q)
- {
- while (!q.empty())
- {
- cout << q.front() << " ";
- q.pop();
- }
- cout << '\n';
- }
- int main()
- {
- int n; cout << "n = "; cin >> n;
- queue <Type> q;
- for (int i = 0; i < n; ++i)
- {
- Type a; cin >> a;
- q.push(a);
- }
- assert(q.size());
- print(q);
- cout << "Число пар: " << count(q) << '\n';
- del(q, n);
- print(q);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement