eolymp
bolt
Try our new interface for solving problems
Problems

Стек неограниченного размера

published at 1/4/24, 9:09:41 pm

include <bits/stdc++.h>

using namespace std; using ll = long long;

int main() { iosbase::syncwith_stdio(0); cin.tie(0); string s; stack<int> st; int x; while(cin >> s){ if(s == "exit"){ cout << "bye"; return 0; } if(s == "push"){ cin >> x; st.push(x); cout << "ok"; } if(s == "pop"){ if(st.empty()) cout << "error"; else { cout << st.top(); st.pop(); } } if(s == "back"){ if(st.empty()) cout << "error"; else cout << st.top(); } if(s == "size"){ cout << st.size(); } if(s == "clear"){ while(!st.empty()) st.pop(); cout << "ok"; } cout << endl; } }