SDUT 1479 数据结构实验之栈:行编辑器

来源:互联网 发布:摩擦纳米发电机 知乎 编辑:程序博客网 时间:2024/06/05 20:03

点击打开题目链接

#include <bits/stdc++.h>using namespace std;stack<char>S;char str[250], _string[250];int main(){    while(gets(_string))    {        int lenth = strlen(_string);        for(int i = 0; i < lenth; i++)        {             if(_string[i] == '#')            {                if(!S.empty())                {                    S.pop();                }            }            else if(_string[i] == '@')            {                if(_string[i+1] == '#' && S.empty())                {                    continue;                }                else                {                    while(!S.empty())                    {                        S.pop();                    }                }            }            else            {                S.push(_string[i]);            }        }        int k = 0;        while(!S.empty())        {            str[++k] = S.top();            S.pop();        }        for(int i = k; i >= 1; i--)        {            cout << str[i];        }        cout << endl;    }    return 0;}


0 0
原创粉丝点击