PTA 7-3 Pop Sequence (25 分)(Data Structures and Algorithms (English))

PTA 7-3 Pop Sequence (25 分)(Data Structures and Algorithms (English))

#include 
#include 
using namespace std;
int main()
{
    int m,n,k,**a;
    cin>>m>>n>>k;
    stack<int> num;
    a=new int*[k];
    for(int i=0;i<k;i++)
    {
        a[i]=new int[n];
        for(int j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    for(int i=0;i<k;i++)
    {
        int t=1,j=0,c=0;
        while(t<=n)
        {
            if(c>=m) break;
            num.push(t);
            c++;
            while(!num.empty()&&num.top()==a[i][j]&&j<n)
            {
                num.pop();
                c--;
                j++;
            }
            t++;
        }
        if(num.empty()) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        while(!num.empty()) num.pop();
    }
    for(int i=0;i<k;i++)
    {
        delete a[i];
    }
    delete a;
    return 0;
}

你可能感兴趣的:(数据结构,pta,数据结构)