zoukankan      html  css  js  c++  java
  • Kattis -Backspace

    Backspace

    /problems/backspace/file/statement/en/img-0001.png
    Bjarki having trouble

    Shortly before the programming contest started, Bjarki decided to update his computer. He didn’t notice anything strange until he started coding in his favorite editor, Bim (Bjarki IMproved). Usually when he’s writing in an editor and presses the backspace key a single character is erased to the left. But after the update pressing that key outputs the character <. He’s tested all the editors on his machine, Bmacs, Neobim, bjedit, NoteBjad++ and Subjark Text, but they all seem to have the same problem. He doesn’t have time to search the web for a solution, and instead decides to temporarily circumvent the issue with a simple program.

    Help Bjarki write a program that takes as input the string that was written in the text editor, and outputs the string as Bjarki intended to write it. You can assume that Bjarki never intended to write the character <, and that Bjarki never pressed the backspace key in an empty line.

    Input

    One line containing the string that was written in the text editor. The length of the string is at most 106106, and it will only contain lowercase letters from the English alphabet as well as the character <.

    Output

    One line containing the string as Bjarki intended to write it.

    Sample Input 1Sample Output 1
    a<bc<
    
    b
    
    Sample Input 2Sample Output 2
    foss<<rritun
    
    forritun
    

    Sample Input 3Sample Output 3
    a<a<a<aa<<
    

    题意

    遇到一个<就删除前一个字母,用栈来做,不过后来输出我还要用数组转换一下,不知道有什么能更方便点的方法

    代码

    #include<bits/stdc++.h>
    using namespace std;
    char aa[1000000];
    int main(){
        stack<char> s;
        string str;
        cin>>str;
        int len=str.size();
        for(int i=0;i<len;i++){
            if(isalpha(str[i]))
            s.push(str[i]);
            else if(str[i]=='<')
            s.pop();
        }
        int cnt=0;
        while(!s.empty()){
            aa[cnt]=s.top();
            s.pop();
            cnt++;
        }
        for(int i=cnt-1;i>=0;i--){
            cout<<aa[i];
        }
        cout<<endl;
        return 0;
    }
  • 相关阅读:
    [哀悼雅安芦山地震]把网页由彩色变成灰度(谷歌、火狐、ie等浏览器兼容)
    hdu 3367 Pseudoforest(最大生成树)
    解决MDK4以上版本没法对STM32软件仿真
    [置顶] java高级工程师struts的内部运行机制详解
    hdu 2141 二分搜索
    windows调试器之Visual C++
    2013年4月19日佳都新太笔试题+解答
    一步步理解Linux进程(3)内核中进程的实现
    什么是你的核心竞争力之一?
    ubuntu创建桌面启动器
  • 原文地址:https://www.cnblogs.com/zhien-aa/p/6279609.html
Copyright © 2011-2022 走看看