Untitled
unknown
c_cpp
4 years ago
1.6 kB
6
Indexable
#include <iostream> #include<bits//stdc++.h> using namespace std; int main() { int t; cin >> t; int c = 1; while (t--) { cout << "Case " << c << ": "; int n; stack <long long> mango; long long max = 0; cin >> n; getchar(); while (n--) { char C; cin >> C; long long num; if(C == 'A') { cin >> num; getchar(); if(num > max) { max = num; } mango.push(max); // break; } if(C == 'Q') { if(mango.empty()) { max = 0; cout << "Empty" << "\n"; } else { cout << mango.top() << "\n"; } // break; } if(C == 'R') { if(mango.empty() == false) { mango.pop(); if(mango.empty() == false) { if(mango.top() < max) { max = mango.top(); } } else { max = 0; } } } } c++; } }
Editor is loading...