バイナリハックイージー / 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) 一.栈基础 栈是一种线性结构 相比较数组,栈对应的操作是数组的子集 只能从一端添加元素,也只能从同一端取出元素,这一端称为栈顶 栈是一种后进先出的数据结构 ...
随机推荐
- magento 2.3安装测试数据
前面我们一步步composer安装Magento2.3,但是没有数据的话各项设置不是很熟悉,所以最好还是安装一下测试数据.下面我们就跟ytkah一起填充数据.假设magento 2.3安装目录是/ww ...
- RestFramework——API设计规范
what's the RESTful RestFramework是一个能快速为我们提供API接口,方便我们编程的框架.API是后端编程人员写的,为了让前端拿数据的一个接口,通常就是以url的形式存在. ...
- CA证书和TLS介绍
数字签名 用自己的私钥给数据加密就叫数字签名 公钥传输威胁 在A和B的通信中,C可以把自己的公钥发给A,让A把C的公钥当成B的公钥,这样的话.B拿到加密数据反而无法解密,而C却可以解密出数据.从而实现 ...
- pro*c的使用
一.什么是Pro*c程序 在oracle数据库管理系统中,有三种访问数据库的方法: 1.用 SQL*Plus,直接输入sql命令以命令行交换的方式访问数据库 2.用一些应用开发 ...
- spring的面向切面实现的两种方式
面向切面:主要应用在日志记录方面.实现业务与日志记录分离开发. spring面向切面有两种实现方式:1.注解 2.xml配置. 1.注解实现如下: (1)配置如下: <?xml version= ...
- 6个炫酷又好用的 Python 工具,个个都很奔放呀
贝多芬写完<第九交响曲>后说:it's done:耶稣在被处死前说:it is done:<指环王>结尾摧毁魔戒后Frodo说:it's done! 我整理完这6个Python ...
- 《全栈性能Jmeter》-1性能方向职业发展
- [LeetCode] 408. Valid Word Abbreviation_Easy
Given a non-empty string s and an abbreviation abbr, return whether the string matches with the give ...
- Tesseract 模块
https://www.cnblogs.com/new-june/p/9249903.html
- android 调用webview控件,为逆向h5app做准备
activity对应layout文件加入: <WebView android:id="@+id/main_web" android:layout_width="ma ...