This commit is contained in:
Arthur K. 2025-05-29 19:24:43 +03:00
commit 810a9654a4
Signed by: wzray
GPG key ID: B97F30FDC4636357
50 changed files with 4450 additions and 0 deletions

59
3/A.cpp Normal file
View file

@ -0,0 +1,59 @@
#include <iostream>
struct Node {
Node* next;
int message;
};
class Stack {
private:
Node* first = nullptr;
public:
void Add(int message) {
Node* new_node = new Node{first, message};
first = new_node;
};
int Poop() {
Node* last = first;
int return_value = last->message;
first = last->next;
delete last;
return return_value;
}
};
int main() {
Stack stack;
int n;
int stack_idx = 0;
std::cin >> n;
int* return_values = new int[n];
for (int i = 0; i < n; ++i) {
char action;
std::cin >> action;
if (action == '+') {
int message;
std::cin >> message;
stack.Add(message);
} else {
return_values[stack_idx] = stack.Poop();
++stack_idx;
}
}
for (int i = 0; i < stack_idx; ++i) {
std::cout << return_values[i] << '\n';
}
delete[] return_values;
return 0;
}