CSU1019: Simple Line Editor
1019: Simple Line Editor
Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 1305 Solved: 457
Description
Early computer used line editor, which allowed text to be created and changed only within one line at a time. However, in line editor programs, typing, editing, and document display do not occur simultaneously (unlike the modern text editor like Microsoft Word). Typically, typing does not enter text directly into the document. Instead, users modify the document text by entering simple commands on a text-only terminal.
Here is an example of a simple line editor which can only process English. In addition, it has two commands. ‘@’ and ‘#’. ‘#’ means to cancel the previous letter, and ‘@’ is a command which invalidates all the letters typed before. That is to say, if you want type “aa”, but have mistakenly entered “ab”, then you should enter ‘#a’ or ‘@aa’ to correct it. Note that if there is no letter in the current document, ‘@’ or ‘#’ command will do nothing.
Input
The first line contains an integer T, which is the number of test cases. Each test case is a typing sequence of a line editor, which contains only lower case letters, ‘@’ and ‘#’.
there are no more than 1000 letters for each test case.
Output
For each test case, print one line which represents the final document of the user. There would be no empty line in the test data.
Sample Input
2
ab#a
ab@aa
Sample Output
aa
aa 题意:模拟水题,碰到#,前面一个字符无效,碰到@前面所有的字符无效,用栈模拟一下就可以了,碰到#pop,碰到@清空。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
const int maxn=;
int T;
char s[maxn];
char ans[maxn];
int main()
{
scanf("%d",&T);
while(T--)
{
stack<char>q;
scanf("%s",s);
int len=strlen(s);
for(int i=;i<len;i++)
{
if(s[i]=='#')
q.pop();
else if(s[i]=='@')
{
while(!q.empty())
q.pop();
}
else
q.push(s[i]);
}
int j=;
while(!q.empty())
{
ans[j++]=q.top();
q.pop();
}
for(int i=;i<j;i++)
printf("%c",ans[i]);
printf("\n");
}
return ;
} /**********************************************************************
Problem: 1019
User: therang
Language: C++
Result: AC
Time:0 ms
Memory:0 kb
**********************************************************************/
CSU1019: Simple Line Editor的更多相关文章
- 中南大学2018年ACM暑期集训前期训练题集(入门题) Q: Simple Line Editor
数据有毒,一个一个读字符是错,整个字符串读入,一次就A了. 总之,数据总是没有错的,还是对c++了解地不够深刻,还有,在比赛中,一定要有勇气重构代码 错误代码: #include<iostrea ...
- CHtmlEditCtrl(1) : Use CHtmlEditCtrl to Create a Simple HTML Editor
I needed a lightweight HTML editor to generate "rich text" emails, so I decided to explore ...
- reactjs simple text editor
import React, { Component } from 'react' import PubSub from 'pubsub' import GlobalVars from 'globalV ...
- How I came to find Linux
http://ianmurdock.com/post/how-i-came-to-find-linux/ lan murdock August 17, 2015 I saw my first Sun ...
- CHtmlEditCtrl (3): More HTML Editor Options
In this version of our HTML Editor, we'll create a floating source view/edit window and we'll implem ...
- JSON Editor 中文文档
JSON Editor JSON Editor 根据定义的JSON Schema 生成了一个Html 表单来对JSON进行编辑.它完整支持JSON Schema 的版本3和版本4,并且它集成了一些流行 ...
- 【软工】[技术博客] 用Monaco Editor打造接近vscode体验的浏览器IDE
[技术博客] 用Monaco Editor打造接近vscode体验的浏览器IDE 官方文档与重要参考资料 官方demo 官方API调用样例 Playground 官方API Doc,但其搜索框不支持模 ...
- lr各种问题以及解决办法
LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen.exe文件 遇到flight界面为空的解决 ...
- 软件测试面试(2)LR篇
一:LoadRunner常见问题整理 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen. ...
随机推荐
- 解决weblogic页面和控制台乱码问题
转自:https://blog.csdn.net/u010995831/article/details/53283746 之前一直有碰到weblogic各种乱码问题,要不就是页面乱码,要不就是控制台乱 ...
- 使用Asp.net Identity 创建用户 、登录代码
1.Identity 1中的注册.登录.注销代码 vs 2013中自带的注册用户代码: 1.首先创建一个ApplicationUser 初始化用户名. 2.使用UserManager创建一个用户,用使 ...
- jquery cloudzoom 3.0,magiczoom 放大镜插件 破解 移除版权信息
jquery Cloud Zoom一款放大镜插件.但是无奈 官方下载的始终有版权信息,因此想到如下方法去掉版权信息,测试可行! 官方网址:http://www.starplugins.com/clou ...
- 【黑金教程笔记之003】【建模篇】【Lab 02 闪耀灯和流水灯】—笔记
(1) 扫描频率和闪耀频率? 模块: /**************************************** module name:flash_module function ...
- 点击button传递消息,但是页面不跳转的解决方法
最近在做一个物联网的项目时遇到的问题:界面上有很多控制开/关灯的button,通过点击button来控制各个灯的亮灭.我需要将获取的不同的点击事件消息,以Socket通信的方式发送给硬件端的服务监听程 ...
- bzoj 1911: [Apio2010]特别行动队【斜率优化dp】
仔细想想好像没学过斜率优化.. 很容易推出状态转移方程\( f[i]=max{f[j]+a(s[i]-s[j])^2+b(s[i]-s[j])+c} \) 然后考虑j的选取,如果选j优于选k,那么: ...
- bzoj 4568: [Scoi2016]幸运数字【树链剖分+线段树+线性基】
一眼做法,好处是好想好写坏处是常数大,容易被卡(bzoj loj 洛谷开O2 能AC,不开有90分-- 大概就是树剖之后维护线段树,在线段树的每个节点上上维护一个线性基,暴力\( 60^2 \)的合并 ...
- 洛谷 P4009 汽车加油行驶问题 【最小费用最大流】
分层图,建k层,设(i,j,0)为点(i,j)的满油状态,全图的流量都是1,因为重复走到一个点没有意义.如果当前点是加油站,那么它向它上左的点连费用为a的边,向下右连费用为a+b的边: 否则,这个点的 ...
- java数组实现买彩票(通过标识符进行判断的思想)
package com.wh.shuzu; import java.util.Random; import java.util.Scanner; /** * 买彩票 * @author 王拥江同学 * ...
- Jmeter+Jenkins+Ant自动化集成环境搭建
搭建环境: JDK:jdk1.8.0_92 Ant:apache-ant-1.9.7 Jmeter: apache-jmeter-3.0 Jenkins:jenkins-2.19.3 具体环境配置 1 ...