题目链接:http://abc043.contest.atcoder.jp/tasks/abc043_b

Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.

To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:

  • The 0 key: a letter 0 will be inserted to the right of the string.
  • The 1 key: a letter 1 will be inserted to the right of the string.
  • The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.

Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?

Constraints

  • 1≦|s|≦10 (|s| denotes the length of s)
  • s consists of the letters 01 and B.
  • The correct answer is not an empty string.

Input

The input is given from Standard Input in the following format:

s

Output

Print the string displayed in the editor in the end.


Sample Input 1

Copy
01B0

Sample Output 1

Copy
00

Each time the key is pressed, the string in the editor will change as follows: 001000.


Sample Input 2

Copy
0BB1

Sample Output 2

Copy
1

Each time the key is pressed, the string in the editor will change as follows: 0(empty)(empty)1.

题解:栈 我也不知道为啥有三组数据过不了 先放这

大晚上来补这道题 后来才发现自己的思路错了 后面输出的顺序完全反了 (栈的特性 最后只需要改改顺序就行了)思路错了居然还过了一大半的数据 有毒 ...

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
return x>y;
}
const int N=;
const int mod=1e9+;
int main()
{
std::ios::sync_with_stdio(false);
string a;
cin>>a;
int len=a.length();
stack <char> q ;
for(int i=;i<len;i++){
if(a[i]=='') q.push('');
else if(a[i]=='') q.push('');
else if(a[i]=='B'){
if(q.size()>)
q.pop();
}
}
char b[];
int t=,i;
while(q.size()>){
b[t++]=q.top();
q.pop();
}
for(i=t-;i>=;i--)
cout<<b[i];
cout<<endl;
return ;
}

バイナリハックイージー / Unhappy Hacking (ABC Edit) (stack)的更多相关文章

  1. Java的堆(Heap)和栈(Stack)的区别

    Java中的堆(Heap)是一个运行时数据区,用来存放类的对象:栈(Stack)主要存放基本的数据类型(int.char.double等8种基本数据类型)和对象句柄. 例1 int a=5; int ...

  2. [置顶] ※数据结构※→☆线性表结构(stack)☆============栈 序列表结构(stack sequence)(六)

    栈(stack)在计算机科学中是限定仅在表尾进行插入或删除操作的线性表.栈是一种数据结构,它按照后进先出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶,需要读数据的时候从栈顶开始弹出数据.栈 ...

  3. PHP实现栈(Stack)数据结构

    栈(Stack),是一种特殊的后进先出线性表,其只能在一端进行插入(插入一般称为压栈.进栈或入栈)和删除(删除一般称为弹栈.退栈或出栈)操作,允许进行插入和删除操作的一端称为栈顶,另一端则称为栈底.栈 ...

  4. C# 堆栈(Stack)和队列(Queue)

    一.什么是堆?(Heap)      堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收.      是程序运行期 ...

  5. 对Android中的堆栈的理解(Stack)

      版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Ln_ZooFa/article/details/50337529 堆栈空间分配 栈(操作系统): ...

  6. 堆(heap)、栈(stack)、方法区(method)

    JVM内存分为3个区:堆(heap).栈(stack).方法区(method) 1.堆(heap):存储的全部对象,每个对象有个与之对应的class信息.即通过new关键字和构造器创建的对象.JVM只 ...

  7. C# 队列(Queue)和 堆栈(Stack)

    C# 队列(Queue)和 堆栈(Stack) C# 队列(Queue) 队列(Queue)代表了一个先进先出的对象集合.当您需要对各项进行先进先出的访问时,则使用队列.当您在列表中添加一项,称为入队 ...

  8. C# 编程中的堆栈(Stack)和队列(Queue)

    一.什么是堆?(Heap)      堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收.      是程序运行期 ...

  9. 我理解的数据结构(二)—— 栈(Stack)

    我理解的数据结构(二)-- 栈(Stack) 一.栈基础 栈是一种线性结构 相比较数组,栈对应的操作是数组的子集 只能从一端添加元素,也只能从同一端取出元素,这一端称为栈顶 栈是一种后进先出的数据结构 ...

随机推荐

  1. sql语句优化(二)

    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引. 建立索引好处  : 之前做的一个项目 , 一个查询10w多条的数据 ,需要20s ,后来加 ...

  2. android下的样式

    android中控件,假如我们把样式都写死在控件的配置文件上的话.一旦改动可谓牵一发而动千军.那么我们能够把样式写在style.xml文件里.然后引用,在API14以上版本号. 该文件位于values ...

  3. VMware Workstation 不可恢复错误 解决方法

    问题: VMware Workstation 不可恢复错误: (vcpu-0) vcpu-0:VERIFY vmcore/vmm/main/cpuid.c:386 bugNr=1036521 日志文件 ...

  4. 001-js-时间格式化

    方法一. // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1 ...

  5. uploadify3.2.1的参数设置

    $('#file_upload').uploadify({ auto:false, //接受true 或 false两个值,当为true时选择文件后会自动上传:为false时只会把选择的文件增加进队列 ...

  6. Spark MLlib之水塘抽样算法(Reservoir Sampling)

    1.理解 问题定义可以简化如下:在不知道文件总行数的情况下,如何从文件中随机的抽取一行? 首先想到的是我们做过类似的题目吗?当然,在知道文件行数的情况下,我们可以很容易的用C运行库的rand函数随机的 ...

  7. 教你写Makefile(很全,含有工作经验的)

    Makefile 值得一提的是,在Makefile中的命令,必须要以[Tab]键开始. 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了 ...

  8. 2019.04.09 电商19 分析carmanage.py

    post(self,request)这个request是干嘛的 有是递归,他调用了那个getcarmanager函数返回的是另一个函数. 这另一个函数负责创建插入数据 def __init__(sel ...

  9. UX求职:FB和微软这些大佬公司看重的UX设计师技能,你还差几条?

    最近是金三银四的求职季,当然,不管你是想求职跳槽,还是想不断充电学习升职加薪,总是要从优秀的一群人中学习. 本文依据 Facebook.微软.Booking 等互联网大佬公司的UX设计师访谈记录,整理 ...

  10. js贪心算法---背包问题

    /* * @param {Object} capacity 背包容量 6 * @param {Object} weights 物品重量 [2,3,4] * @param {Object} values ...