バイナリハックイージー / Unhappy Hacking (ABC Edit) (stack)

题目链接: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.

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

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <cstdio>
 5 #include <vector>
 6 #include <cstdlib>
 7 #include <iomanip>
 8 #include <cmath>
 9 #include <ctime>
10 #include <map>
11 #include <set>
12 #include <queue>
13 #include <stack>
14 using namespace std;
15 #define lowbit(x) (x&(-x))
16 #define max(x,y) (x>y?x:y)
17 #define min(x,y) (x<y?x:y)
18 #define MAX 100000000000000000
19 #define MOD 1000000007
20 #define pi acos(-1.0)
21 #define ei exp(1)
22 #define PI 3.141592653589793238462
23 #define INF 0x3f3f3f3f3f
24 #define mem(a) (memset(a,0,sizeof(a)))
25 typedef long long ll;
26 ll gcd(ll a,ll b){
27     return b?gcd(b,a%b):a;
28 }
29 bool cmp(int x,int y)
30 {
31     return x>y;
32 }
33 const int N=10005;
34 const int mod=1e9+7;
35 int main()
36 {
37     std::ios::sync_with_stdio(false);
38     string a;
39     cin>>a;
40     int len=a.length();
41     stack <char> q ;
42     for(int i=0;i<len;i++){
43         if(a[i]==‘1‘){
44             q.push(‘1‘);
45         }
46         else if(a[i]==‘0‘){
47             q.push(‘0‘);
48         }
49         else if(a[i]==‘B‘){
50             if(q.size()>0)
51                 q.pop();
52         }
53     }
54     while(q.size()>0){
55         cout<<q.top();
56         q.pop();
57     }
58     cout<<endl;
59     return 0;
60 }
时间: 2024-08-13 09:25:28

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

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

Java中的堆(Heap)是一个运行时数据区,用来存放类的对象:栈(Stack)主要存放基本的数据类型(int.char.double等8种基本数据类型)和对象句柄. 例1 int a=5; int b=5; System.out.println(a==b); 以上例子中,编译器首先处理int a=5,首先在栈中创建一个引用a,然后在栈中查找是否有5这个值,如果有,则将a指向5,如果没有,则创建一个5,再将a指向5.当处理int b=5时,由于栈中肯定已经存在5,直接将b指向5,这样a和b都指向

STM32启动时RAM空间堆(Heap)和栈(stack)的分配 总结

STM32再启动的时候RAM首先分配给使用到的全局变量,及调用库占用的一些数据(不太清楚是什么数据) ,然后再将剩余的空间分配给Heap和stack. 以下是网上关于Heap和Stack的说: (1)栈区(stack):由编译器自动分配和释放,存放函数的参数值.局部变量的值等,其操作方式类似 于数据结构中的栈. (2)堆区(heap):一般由程序员分配和释放,若程序员不释放,程序结束时可能由操作系统回收.分配 方式类似于数据结构中的链表. (3)全局区(静态区)(static):全局变量和静态变

从头认识java-9.8 栈(Stack)

这一章节我们来讨论一下栈(Stack). 1.特性 先进后出,当一个元素压进栈里面,他就会处于栈的底部,然后,另一个再压进来,盖在原来的元素上面,原来的元素想出去,只有等上面的元素先顶出栈才有机会. 2.方法演示 package com.ray.ch09; import java.util.Arrays; import java.util.Stack; public class Test { public static void main(String[] args) { Stack<Integ

C# 堆栈(Stack)

堆栈(Stack)代表了一个后进先出的对象集合. using System; using System.Collections; namespace CollectionsApplication { class Program { static void Main(string[] args) { Stack st = new Stack(); st.Push('A'); st.Push('M'); st.Push('G'); st.Push('W'); Console.WriteLine("C

特殊的线性表(stack)

1. 什么是栈? 栈(stack)是限定仅在表尾进行插入和删除操作的线性表. 2. 栈的特点: 1.) 栈又称为后进先出(Last In First out)的线性表,栈元素具有线性关系,即前驱后继关系. 2.) 栈的特殊之处在于:它的栈底是固定的,只允许在栈顶进行插入和删除操作. 3. 栈的顺序存储结构(Java数组实现): // 栈的数组实现, 底层使用数组: public class ArrayStack<T> { private Object[] arr; // 数组首元素作为栈底,因

36. C# -- 堆栈(stack)

堆栈(Stack)代表了一个后进先出的对象集合. using System; using System.Collections; namespace CollectionsApplication {     class Program {         static void Main(string[] args) {             Stack st = new Stack();             st.Push('A');             st.Push('M');

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

JVM内存分为3个区:堆(heap).栈(stack).方法区(method) 1.堆(heap):存储的全部对象,每个对象有个与之对应的class信息.即通过new关键字和构造器创建的对象.JVM只有一个堆被所有线程共享.堆是垃圾收集管理的主要区域. 2.栈(stack):每个线程包含一个栈区,栈中只保存基本数据类型和自定义对象的引用.每个栈中的数据都是私有的,其他栈不能访问.栈又分为3个区:基本类 型变量区.执行环境上下文.操作指令区. 3.方法区(method):方法区又叫做静态区.和堆一

Windows C++ 非递归式(stack)深度优先遍历目录

1 #include <Windows.h> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <stack> 6 7 typedef void (__stdcall *P_WALK_DIR_CALLBACK)(const std::string &In_strFilePath); 8 9 int WalkDir(const char *In_p

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

一.什么是堆?(Heap)      堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收.      是程序运行期间动态分配的内存空间,你可以根据程序的运行情况确定要分配的堆内存的大小. 二.什么是栈?(Stack)      栈是有顺序的,是一片连续的内存域,保持着先进后出的原则,由系统自动分配和维护.      是编译期间就分配好的内存空间,因此代码中必须就栈的大小有明确的定义.      表尾允许进行插入