summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-10 23:06:37 +0400
committerAndrew <saintruler@gmail.com>2021-02-10 23:06:37 +0400
commit8090e4beb10133f5df865a219a87140b50324fda (patch)
treed3e5412c5e1c3eb3a747da9dea16ccdff6a54341
parent43a261149b8bd3d811a330ff6cb6c1e774fd14d7 (diff)
Добавил решение 14 задачи
-rw-r--r--structures/Makefile7
-rw-r--r--structures/queue.h33
-rw-r--r--structures/task14.cpp45
3 files changed, 84 insertions, 1 deletions
diff --git a/structures/Makefile b/structures/Makefile
index d2d7739..7dacd52 100644
--- a/structures/Makefile
+++ b/structures/Makefile
@@ -1,5 +1,5 @@
CXX=g++
-CFLAGS=-Wall
+CFLAGS=-g -Wall
COMPILE=$(CXX) $(CFLAGS)
task5:
@@ -10,5 +10,10 @@ task8:
test8: task8
printf "10\n1 1 2 3 2 4 3 5 4 1" | ./task.out
+task14:
+ $(COMPILE) -o task.out task14.cpp
+test14: task14
+ printf "10\na 2 - e * ^ f + & 0 )" | ./task.out
+
clean:
rm task.out
diff --git a/structures/queue.h b/structures/queue.h
new file mode 100644
index 0000000..368da01
--- /dev/null
+++ b/structures/queue.h
@@ -0,0 +1,33 @@
+#pragma once
+
+struct queue
+{
+ int inf;
+ queue *next;
+};
+
+void push(queue *&h, queue *&t, int x)
+{
+ queue *r = new queue;
+ r->inf = x;
+ r->next = NULL;
+
+ if (!h && !t)
+ h = t = r;
+ else
+ {
+ t->next = r;
+ t = r;
+ }
+}
+
+int pop(queue *&h, queue *&t)
+{
+ queue *r = h;
+ int i = h->inf;
+ h = h->next;
+
+ if (!h) t = NULL;
+ delete r;
+ return i;
+}
diff --git a/structures/task14.cpp b/structures/task14.cpp
new file mode 100644
index 0000000..fcd9d63
--- /dev/null
+++ b/structures/task14.cpp
@@ -0,0 +1,45 @@
+#include <iostream>
+#include "queue.h"
+
+using namespace std;
+
+void result(queue *&h, queue *&t, queue *&hr, queue *&tr)
+{
+ while (h)
+ {
+ int el = char(pop(h, t));
+ if ( '0' <= el && el <= '9'
+ || 'a' <= el && el <= 'z'
+ || 'A' <= el && el <= 'Z' )
+ {
+ push(hr, tr, int(el));
+ }
+ }
+}
+
+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;
+
+}