继队列之后,我们又来学习一种新的数据结构——栈。将队列的头部封闭后,就构成了栈这种数据结构,原来队列头部就是栈底,原来队列的尾部就是栈顶。栈与队列的不同就在于栈的底端是封闭的。所以,栈的插入和删除操作只能在栈的一端进行,即栈顶。栈的插入操作称为入栈,删除操作称为出栈。
//#include<stdio.h>
//#include<string.h>
//#include<algorithm>
//using namespace std;
//char a[20];char b[20005];
//char ss[20001][20];
//int main()
//{
// int t,n;
// scanf("%d",&t);
// while(t--)
// {int x=0;
// scanf("%d",&n);
// for(int i=0; i<n; i++)
// {
// scanf("%s",a);
// if(strcmp(a,"push")==0)
// {
// scanf("%s",b);
// strcpy(ss[x++],b);
// }
// if(x!=0&&strcmp(a,"pop")==0)
// {
// x--;
// }
// }
// if(x>0)
// {
// for(int i=x-1; i>0; i--)
// {
// printf("%s ",ss[i]);
// }
// printf("%s",ss[0]);
// printf("\n");
// }
// else
// {
// printf("no eggs!\n");
// }
//
// }
// return 0;
//}
底________________顶
|
底—————————顶
Input
第一行输入一个数T,表示有T组数据
第二行输入一个数N,表示有N种操作
接下来N行,每行一种操作,push表示将编号为x的鸡蛋放入栈中,pop表示拿走栈顶部的一个鸡蛋。
数据输入保证合法,栈中没有鸡蛋时不考虑出栈操作!
第二行输入一个数N,表示有N种操作
接下来N行,每行一种操作,push表示将编号为x的鸡蛋放入栈中,pop表示拿走栈顶部的一个鸡蛋。
数据输入保证合法,栈中没有鸡蛋时不考虑出栈操作!
Output
在N种操作完成以后,再将栈中的鸡蛋逐个出栈,按出栈顺序打印鸡蛋上的编号,两个编号之间用空格隔开。如果已没有鸡蛋,则输出"no eggs!"(不包含引号)。
Sample Input
1 3 push 3 push 2 push 1
Sample Output
1 2 3
Hint
数组模拟、变量标记
○| ̄|\_
○| ̄|\_
//#include<stdio.h>
//#include<string.h>
//#include<algorithm>
//using namespace std;
//char a[20];char b[20005];
//char ss[20001][20];
//int main()
//{
// int t,n;
// scanf("%d",&t);
// while(t--)
// {int x=0;
// scanf("%d",&n);
// for(int i=0; i<n; i++)
// {
// scanf("%s",a);
// if(strcmp(a,"push")==0)
// {
// scanf("%s",b);
// strcpy(ss[x++],b);
// }
// if(x!=0&&strcmp(a,"pop")==0)
// {
// x--;
// }
// }
// if(x>0)
// {
// for(int i=x-1; i>0; i--)
// {
// printf("%s ",ss[i]);
// }
// printf("%s",ss[0]);
// printf("\n");
// }
// else
// {
// printf("no eggs!\n");
// }
//
// }
// return 0;
//}