summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-10 23:15:28 +0400
committerAndrew <saintruler@gmail.com>2021-02-10 23:15:28 +0400
commita7a0646a34a1430568ec5cb22534f24c886d127b (patch)
tree081059067e69c73960f1b92e76680f7a24d4b047
parent8090e4beb10133f5df865a219a87140b50324fda (diff)
Добавил решение 18 задачи
-rw-r--r--structures/Makefile6
-rw-r--r--structures/task18.cpp48
2 files changed, 54 insertions, 0 deletions
diff --git a/structures/Makefile b/structures/Makefile
index 7dacd52..7dcb9d1 100644
--- a/structures/Makefile
+++ b/structures/Makefile
@@ -15,5 +15,11 @@ task14:
test14: task14
printf "10\na 2 - e * ^ f + & 0 )" | ./task.out
+task18:
+ $(COMPILE) -o task.out task18.cpp
+test18: task18
+ printf "8\n1 1 2 2 3 4 5 5" | ./task.out
+ printf "11\n1 1 1 2 2 1 1 3 4 5 5" | ./task.out
+
clean:
rm task.out
diff --git a/structures/task18.cpp b/structures/task18.cpp
new file mode 100644
index 0000000..f78c9ba
--- /dev/null
+++ b/structures/task18.cpp
@@ -0,0 +1,48 @@
+#include <iostream>
+#include "queue.h"
+
+using namespace std;
+
+void result(queue *&h, queue *&t, queue *&hr, queue *&tr)
+{
+ int prev;
+ prev = pop(h, t);
+ push(hr, tr, prev);
+
+ while (h)
+ {
+ int cur = pop(h, t);
+ if (cur != prev)
+ {
+ prev = cur;
+ push(hr, tr, cur);
+ }
+ }
+}
+
+int main()
+{
+ int n;
+ cout << "n = ";
+ cin >> n;
+
+ queue *head = NULL;
+ queue *tail = NULL;
+ char x;
+ for (int i = 0; i < n; i++)
+ {
+ cin >> x;
+ push(head, tail, int(x));
+ }
+
+ queue *head_res = NULL;
+ queue *tail_res = NULL;
+
+ result(head, tail, head_res, tail_res);
+ while (head_res)
+ cout << char(pop(head_res, tail_res)) << " ";
+ cout << endl;
+
+ return 0;
+
+}