Untitled

 avatar
unknown
plain_text
4 years ago
1.6 kB
4
Indexable
#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++;
    }

}

Editor is loading...