愚蠢的操作

#include "bits/stdc++.h"
using namespace std;

int main()
{
    int n;
    while(cin >> n)
    {
        int a[n];

        for(int i=0;i < n;i++)
            cin >> a[i];

        stack<int>b;
        int k;
        for( k=1;k <= a[0];k++){
            b.push(k);
            cout << "P";
        }
        b.pop();cout << "Q";
        k = k-1;
        for(int i=1;i < n;i++)
        {
            if(a[i] > a[i-1])
            {
                while(k < a[i])
                {
                    b.push(++k);
                    cout << "P";
                }
                cout << "Q";
                b.pop();
            }
            else
            {
                if(b.top() != a[i])
                {cout << " error";break;}
                else
                {cout << "Q";b.pop();}
            }
        }
        cout << endl;
    }
}

写的很辣鸡

原文地址:https://www.cnblogs.com/cunyusup/p/7769116.html