Kattis -Backspace
Backspace
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 1 | Sample Output 1 |
|---|---|
a<bc< |
b |
| Sample Input 2 | Sample Output 2 |
|---|---|
foss<<rritun |
forritun |
| Sample Input 3 | Sample Output 3 |
|---|---|
a<a<a<aa<< |
题意
遇到一个<就删除前一个字母,用栈来做,不过后来输出我还要用数组转换一下,不知道有什么能更方便点的方法
代码
#include<bits/stdc++.h>
using namespace std;
char aa[];
int main(){
stack<char> s;
string str;
cin>>str;
int len=str.size();
for(int i=;i<len;i++){
if(isalpha(str[i]))
s.push(str[i]);
else if(str[i]=='<')
s.pop();
}
int cnt=;
while(!s.empty()){
aa[cnt]=s.top();
s.pop();
cnt++;
}
for(int i=cnt-;i>=;i--){
cout<<aa[i];
}
cout<<endl;
return ;
}
Kattis -Backspace的更多相关文章
- Cygwin中解决vi编辑器方向键和Backspace键不好使、安装vim的方法
修改.virc文件(如果没有就创建)vi .virc 添加以下内容set nocpset backspace=start,indent,eol 保存退出:wq 如果是vim就修改.vimrc文件. 由 ...
- 在网页中让Backspace按键不可作为退回使用
这也是转载的,让BackSpace按键不可作为退回使用,在textbox中设置readonly时,将退回禁用. <script type="text/javascript"& ...
- 在IE下,如果在readonly的input里面键入backspace键,会触发history.back()
在IE下,如果在readonly的input里面键入backspace键,会触发history.back(), 用以下jQuery代码修正之 $("input[readOnly]" ...
- js禁止Backspace键使浏览器后退
在项目中遇到按下Backspace键让浏览器后退的问题,上网搜了几种解决方案都不太理想.于是集众人之智,采众家之长,归纳如下: 这里主要参考博客http://q821424508.iteye.com/ ...
- oracle 解决backspace和上下键使用出现乱码
在bash提示符下,使用Del键或者Backspace键都能删除光标左右的字符,但是一旦进入sqlplus之后,只能使用Del键来删除光标左侧的字符,使用Backspace键则显示^H,使用ctrl+ ...
- securityCRT mongoDB 命令行删除(backspace/delete)无效问题
1.MongoDB Shell中退格键使用的问题. 利用SecureCRT工具访问linux的时候,在使用MongoDB的交互式shell的时候,退格键(Backspace)无法使用,导致无法修改输入 ...
- IE下只读INPUT键入BACKSPACE 后退问题(readonly='true')
在IE下,如果在readonly的input里面键入backspace键,会触发history.back(), 用以下jquery代码修正之 $("input[readOnly]" ...
- js禁用回退键backspace解决办法
本文摘自http://q821424508.iteye.com/blog/1587025 以下为2.0版本,支持IE,firefox,chrome[这三款浏览器经过测试]等浏览器 window.onl ...
- JavaScript屏蔽Backspace键
原文:http://www.cnblogs.com/xdp-gacl/p/3785806.html 今天在IE浏览器下发现,当把使用readonly="readonly"属性将文本 ...
随机推荐
- CentOS7环境RabbitMQ集群配置管理(转载)
CentOS7环境RabbitMQ集群配置管理(转载) CentOS7系统内核版本:3.10.0-514.26.2.el7.x86_64 一.对应主机host地址(三台主机host文件要保持一致) ...
- 前端开发—BOM对象DOM文档对象操作
BOM 浏览器对象 BOM:Browser Object Model 操作浏览器,需要调用window对象,它是所有浏览器都支持的对象,表示的就是浏览器窗口 window对象可以通过点调用子对象 wi ...
- Nginx1.14.2新增tcp/udp代理stream
[root@rhel nginx-1.12.1]# ./configure --help --help print this message --prefix=PATH set installatio ...
- with as递归调用
一.递归调用--在代码中偶尔看到以记之,便于下次学习 https://blog.csdn.net/johnf_nash/article/details/78681060 --查询节点及其下所有子节点 ...
- python笔记10-----便捷网络数据NLTK语料库
1.NLTK的概念 NLTK:Natural language toolkit,是一套基于python的自然语言处理工具. 2.NLTK中集成了语料与模型等的包管理器,通过在python编辑器中执行. ...
- 训练1-T
一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7,则称其为与7相关的数.求所有小于等于N的与7无关的正整数的平方和. 例如:N = 8,<= 8与7无关的数包括:1 2 ...
- Java中发邮件的6种方法
1.官方标准JavaMail Sun(Oracle)官方标准,功能强大,用起来比较繁琐. 官方资料:http://www.oracle.com/technetwork/java/javamail/in ...
- android AndroidManifest.xml 属性详细解析
一.关于AndroidManifest.xml AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activiti ...
- 【Educational Codeforces Round 48 (Rated for Div. 2) C】 Vasya And The Mushrooms
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 显然在没有一直往右走然后走到头再往上走一格再往左走到头之前. 肯定是一直在蛇形走位.. 这个蛇形走位的答案贡献可以预处理出来.很容易 ...
- Elasticsearch架构原理
架构原理 本书作为 Elastic Stack 指南,关注于 Elasticsearch 在日志和数据分析场景的应用,并不打算对底层的 Lucene 原理或者 Java 编程做详细的介绍,但是 Ela ...