hrbust 1577 Prince and little Princess-1

来源:互联网 发布:搜索引擎优化广告 编辑:程序博客网 时间:2024/05/22 04:55

这是第二次做栈的题,其实对于现在的自己,本应该早些把它做出来,可是一直懒惰,没有抓住学习的最好时间,才导致今天的失败,

不过其实我觉得虽然很遗憾不能去参加省赛去,但我心里还是决定要一直坚持下去,从现在慢慢的好好从基础学起,不会在放弃机会了,

because i think 坚持就是胜利~~~加油~~~

#include<iostream>#include<stdio.h>#include<string.h>using namespace std;int main(){    int stack[1024];    char str[15];    int n, i;    while(cin >> n)    {        for(i=0; i<n; i++)        {            cin >> stack[i];        }        int top=i-1;          while(cin >> str)        {            if(strcmp(str, "end")==0) break;  //结束            else if(strcmp(str, "pop")==0)            {                top--;                         //出栈            }            else if(strcmp(str, "top")==0)            {                cout << stack[top]<<endl;      //查询栈顶元素            }            else if(strcmp(str, "empty")==0)            {                if(top==-1) cout << "T^T"<< endl;                else cout << "^_^" << endl;     //判定栈是否为空            }            else if(strcmp(str, "push")==0)            {                top++;                cin >> stack[top];              //将元素入栈            }        }    }    return 0;}

原创粉丝点击