题目地址
https://pta.patest.cn/pta/test/16/exam/4/question/665
5-3 Pop Sequence (25分)
Given a stack which can keep MM numbers at most. Push NN numbers in the order of 1, 2, 3, ..., NN and pop randomly. You are supposed to tell if a given sequence of numbers is a possible pop sequence of the stack. For example, if MM is 5 and NN is 7, we can obtain 1, 2, 3, 4, 5, 6, 7 from the stack, but not 3, 2, 1, 7, 5, 6, 4.
Input Specification:
Each input file contains one test case. For each case, the first line contains 3 numbers (all no more than 1000): MM (the maximum capacity of the stack), NN (the length of push sequence), and KK (the number of pop sequences to be checked). Then KK lines follow, each contains a pop sequence of NN numbers. All the numbers in a line are separated by a space.
Output Specification:
For each pop sequence, print in one line "YES" if it is indeed a possible pop sequence of the stack, or "NO" if not.
Sample Input:
5 7 51 2 3 4 5 6 73 2 1 7 5 6 47 6 5 4 3 2 15 6 4 3 7 2 11 7 6 5 4 3 2
Sample Output:
YESNONOYESNO
/*评测结果时间 结果 得分 题目 编译器 用时(ms) 内存(MB) 用户2017-07-08 15:55 答案正确 25 5-3 gcc 3 1 测试点结果测试点 结果 得分/满分 用时(ms) 内存(MB)测试点1 答案正确 15/15 2 1测试点2 答案正确 3/3 2 1测试点3 答案正确 2/2 2 1测试点4 答案正确 2/2 3 1测试点5 答案正确 1/1 2 1测试点6 答案正确 2/2 1 1*/#include#define MAXLEN 1000/*下面这段代码只能拿18/25分 int main(){ int i,j,m,n,k,last,flag,temp; scanf("%d %d %d",&m,&n,&k); for (i=0;i m) flag=0; last=temp; } if(flag==0) printf("NO\n"); else printf("YES\n"); }}*/struct stack{ int data[MAXLEN]; int top; int max;};struct stack workstack;int GetTop(struct stack stc){ if(stc.top>=0) return stc.data[stc.top]; else return 0;}int Push(struct stack *stc,int item){ if (stc->top==MAXLEN-1) return 0; else { stc->data[++(stc->top)]=item;// printf("--PUSH %d,%d\n",stc->data[(stc->top)],stc->top);//test return 1; }}int Pop(struct stack *stc){ if(stc->top<0) return 0; else{// printf("--POP %d,%d\n",stc->data[(stc->top)],stc->top);//test return stc->data[(stc->top)--]; }}int main(){ int i,j,m,n,k,numforpush,errorflag,temp; scanf("%d %d %d",&m,&n,&k); workstack.max=m; for (i=0;i