Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int n;
- cin >> n;
- stack<ll>st;
- st.push(1);
- ll op=0;
- int f=0;
- int o=0;
- while (n--) {
- string s;
- cin >> s;
- if (s=="for") {
- int x; cin >> x;
- if (st.top()>UINT_MAX) o=1;
- st.push(st.top()*x);
- }
- else if (s=="add") {
- if (o) f=1;
- op+=st.top();
- }
- else {
- st.pop();
- if (st.top()<=UINT_MAX) o=0;
- }
- if (op>UINT_MAX) f=1;
- }
- if (op>UINT_MAX || f) cout << "OVERFLOW!!!";
- else cout << op;
- return 0;
- }
- /*
- 13
- for 100
- for 100
- for 100
- for 100
- for 100
- for 100
- end
- end
- end
- end
- end
- end
- add
- *UINT_MAX
- */
Advertisement
Add Comment
Please, Sign In to add comment