zoukankan      html  css  js  c++  java
  • CSU1019: Simple Line Editor

    1019: Simple Line Editor

            Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 1305     Solved: 457    


    Description

     

    Early computer used line editor, which allowed text to be created and changed only within one line at a time. However, in line editor programs, typing, editing, and document display do not occur simultaneously (unlike the modern text editor like Microsoft Word). Typically, typing does not enter text directly into the document. Instead, users modify the document text by entering simple commands on a text-only terminal. 

    Here is an example of a simple line editor which can only process English. In addition, it has two commands. ‘@’ and ‘#’. ‘#’ means to cancel the previous letter, and ‘@’ is a command which invalidates all the letters typed before. That is to say, if you want type “aa”, but have mistakenly entered “ab”, then you should enter ‘#a’ or ‘@aa’ to correct it. Note that if there is no letter in the current document, ‘@’ or ‘#’ command will do nothing.

    Input

     

    The first line contains an integer T, which is the number of test cases. Each test case is a typing sequence of a line editor, which contains only lower case letters, ‘@’ and ‘#’.

    there are no more than 1000 letters for each test case.

    Output

     

    For each test case, print one line which represents the final document of the user. There would be no empty line in the test data.

    Sample Input

    2
    ab#a
    ab@aa
    

    Sample Output

    aa
    aa

    题意:模拟水题,碰到#,前面一个字符无效,碰到@前面所有的字符无效,用栈模拟一下就可以了,碰到#pop,碰到@清空。
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <stack>
    using namespace std;
    const int maxn=1005;
    int T;
    char s[maxn];
    char ans[maxn];
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            stack<char>q;
            scanf("%s",s);
            int len=strlen(s);
            for(int i=0;i<len;i++)
            {
                if(s[i]=='#')
                    q.pop();
                else if(s[i]=='@')
                {
                    while(!q.empty())
                        q.pop();
                }
                else
                    q.push(s[i]);
            }
            int j=0;
            while(!q.empty())
            {
                ans[j++]=q.top();
                q.pop();
            }
            for(int i=0;i<j;i++)
                printf("%c",ans[i]);
            printf("
    ");
        }
        return 0;
    }
    
    
    /**********************************************************************
        Problem: 1019
        User: therang
        Language: C++
        Result: AC
        Time:0 ms
        Memory:0 kb
    **********************************************************************/
  • 相关阅读:
    【Visual C++】游戏开发笔记之六——游戏画面绘图(三)透明特效的制作方法
    【不定期更新】游戏开发中的一些良好习惯与技术技巧
    【Visual C++】游戏开发笔记之七——基础动画显示(一)定时器的使用
    【超级经典】程序员装B指南(转)
    Gentoo安装小记
    图形学中的贴图采样、走样与反走样等
    面试题之银行业务调度系统
    四川雅安芦山加油挺住
    ZOJ 3223 Journey to the Center of the Earth
    android中ListView拖动时背景黑色的问题
  • 原文地址:https://www.cnblogs.com/jkzr/p/10030702.html
Copyright © 2011-2022 走看看