バイナリハックイージー / 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 letter0
will be inserted to the right of the string. - The
1
key: a letter1
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
0
,1
andB
. - 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
01B0
Sample Output 1
00
Each time the key is pressed, the string in the editor will change as follows: 0
, 01
, 0
, 00
.
Sample Input 2
0BB1
Sample Output 2
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)的更多相关文章
- Java的堆(Heap)和栈(Stack)的区别
Java中的堆(Heap)是一个运行时数据区,用来存放类的对象:栈(Stack)主要存放基本的数据类型(int.char.double等8种基本数据类型)和对象句柄. 例1 int a=5; int ...
- [置顶] ※数据结构※→☆线性表结构(stack)☆============栈 序列表结构(stack sequence)(六)
栈(stack)在计算机科学中是限定仅在表尾进行插入或删除操作的线性表.栈是一种数据结构,它按照后进先出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶,需要读数据的时候从栈顶开始弹出数据.栈 ...
- PHP实现栈(Stack)数据结构
栈(Stack),是一种特殊的后进先出线性表,其只能在一端进行插入(插入一般称为压栈.进栈或入栈)和删除(删除一般称为弹栈.退栈或出栈)操作,允许进行插入和删除操作的一端称为栈顶,另一端则称为栈底.栈 ...
- C# 堆栈(Stack)和队列(Queue)
一.什么是堆?(Heap) 堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收. 是程序运行期 ...
- 对Android中的堆栈的理解(Stack)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Ln_ZooFa/article/details/50337529 堆栈空间分配 栈(操作系统): ...
- 堆(heap)、栈(stack)、方法区(method)
JVM内存分为3个区:堆(heap).栈(stack).方法区(method) 1.堆(heap):存储的全部对象,每个对象有个与之对应的class信息.即通过new关键字和构造器创建的对象.JVM只 ...
- C# 队列(Queue)和 堆栈(Stack)
C# 队列(Queue)和 堆栈(Stack) C# 队列(Queue) 队列(Queue)代表了一个先进先出的对象集合.当您需要对各项进行先进先出的访问时,则使用队列.当您在列表中添加一项,称为入队 ...
- C# 编程中的堆栈(Stack)和队列(Queue)
一.什么是堆?(Heap) 堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收. 是程序运行期 ...
- 我理解的数据结构(二)—— 栈(Stack)
我理解的数据结构(二)-- 栈(Stack) 一.栈基础 栈是一种线性结构 相比较数组,栈对应的操作是数组的子集 只能从一端添加元素,也只能从同一端取出元素,这一端称为栈顶 栈是一种后进先出的数据结构 ...
随机推荐
- 20190122 loop
declare a number; v_begin date := to_date('201901013','yyyymmdd'); v_end date := to_date('20190119', ...
- 报错解决——DateTimeField *** received a naive datetime (***) while time zone support is active
这是一个跟时区有关的问题,报错中说到datetime字段得到一个naive datetime,而不是支持time zone的active datetime由于Django的设置中米哦人USE_TZ设置 ...
- TADOConnection组件
该组件用于建立数据库的连接.ADO的数据源组件和命令组件可以通过该组件运行命令及数据库中提取数据等. 该组件用于建立数据库的连接,该连接可被多个数据集所共享,但是并不是应用程序中必须的,因为ADO数据 ...
- javascript篇-typeof,instanceof,constructor,toString判断数据类型的用法和区别
javascript基本数据类型有:string,number,Boolean,undefined,null 引用类型(复杂类型):object, ES6中新增了一种数据类型:Symbol 以上数据类 ...
- Python实现文字聊天室
你是否想过用所学的Python开发一个图形界面的聊天室程序啊? 像这样的: 如果你想开发这样一个有点怀旧风格的聊天程序,那么可以接着看: 要开发这个聊天程序,你需要具备以下知识点: asyncore ...
- 高危Windows系统 SMB/RDP远程命令执行漏洞 手工修复办法
1.Windows Update更新补丁方式: 更新方法:点击“开始”->“控制面板”->“Windows Update” ,点击“检查更新”-“安装更新”: 2.检查安装结果: 点击“ ...
- C++ 类定义
C++ 类定义 定义一个类,本质上是定义一个数据类型的蓝图.这实际上并没有定义任何数据,但它定义了类的名称意味着什么,也就是说,它定义了类的对象包括了什么,以及可以在这个对象上执行哪些操作. 类定义是 ...
- Python使用suds调用webservice报错解决方法:AttributeError: 'Document' object has no attribute 'set'
使用python的suds包调用webservice服务接口,报错:AttributeError: 'Document' object has no attribute 'set' 调用服务接口代码: ...
- unity3d-游戏实战突出重围,第三天 绘制数字
实现效果: 准备资源 using UnityEngine; using System.Collections; public class hznum : MonoBehaviour { //存储图片资 ...
- VirtualBox下扩容vdi文件
VirtualBox下扩容vdi文件 版本:VirtualBox 5.0.14 之前VirtualBox创建的虚拟机的vdi文件过小,无法满足新的实验需求,扩容vdi文件的方法如下: 比如我这里将RH ...