Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.6 kB
2
Indexable
Never
#include <iostream>
#include<bits//stdc++.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    int c = 1;
    long long max = 0;


    while (t--)
    {
        cout << "Case " << c << ": ";

        stack <long long> mango;
        int n;
        cin >> n;
        char temp;
        cin >> temp;

        while (n--)
        {
            char C;
            cin >> C;
            long long num;

            if(C == 'A')

            {
                cin >> num;
                cin >> temp;
                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++;
    }

}