From b3f28bca3da03a81fb7a72f85f563360d4f13b0f Mon Sep 17 00:00:00 2001 From: Andrew Date: Thu, 11 Feb 2021 00:24:49 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B0=D1=80=D0=B8=D0=B5?= =?UTF-8?q?=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structures/task14.cpp | 4 ++-- structures/task18.cpp | 4 ++-- structures/task25.cpp | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'structures') diff --git a/structures/task14.cpp b/structures/task14.cpp index fcd9d63..6804a60 100644 --- a/structures/task14.cpp +++ b/structures/task14.cpp @@ -3,7 +3,7 @@ using namespace std; -void result(queue *&h, queue *&t, queue *&hr, queue *&tr) +void solve(queue *&h, queue *&t, queue *&hr, queue *&tr) { while (h) { @@ -35,7 +35,7 @@ int main() queue *head_res = NULL; queue *tail_res = NULL; - result(head, tail, head_res, tail_res); + solve(head, tail, head_res, tail_res); while (head_res) cout << char(pop(head_res, tail_res)) << " "; cout << endl; diff --git a/structures/task18.cpp b/structures/task18.cpp index fcc0c67..b954bf0 100644 --- a/structures/task18.cpp +++ b/structures/task18.cpp @@ -3,7 +3,7 @@ using namespace std; -void result(queue *&h, queue *&t, queue *&hr, queue *&tr) +void solve(queue *&h, queue *&t, queue *&hr, queue *&tr) { int prev; prev = pop(h, t); @@ -38,7 +38,7 @@ int main() queue *head_res = NULL; queue *tail_res = NULL; - result(head, tail, head_res, tail_res); + solve(head, tail, head_res, tail_res); while (head_res) cout << pop(head_res, tail_res) << " "; cout << endl; diff --git a/structures/task25.cpp b/structures/task25.cpp index fde664c..730e465 100644 --- a/structures/task25.cpp +++ b/structures/task25.cpp @@ -10,15 +10,23 @@ int main() cin >> n; stack *s = NULL; - char* buf = new char[32]; + // Так как в int не помещаются числа длиной более 10 + // знаков, буфера такого размера будет достаточно. + char* buf = new char[16]; for (int i = 0; i < n; i++) { cin >> buf; + + // Если первый элемент буфера -- цифра, то можно считать, что + // в буфере находится число и его нужно преобразовать в int. if ('0' <= buf[0] && buf[0] <= '9') { int i = atoi(buf); push(s, i); } + // Иначе, скорее всего, в буфере находится операция. + // Если первый символ не является допустимой операцией, + // то ничего не происходит. else { switch (buf[0]) @@ -44,6 +52,7 @@ int main() } } + // В результате выполнения выражения в стеке должно остаться одно число. int result = pop(s); cout << "Result = " << result << endl; -- cgit v1.2.3