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. ...
随机推荐
- LA 4670 Dominating Patterns (AC自动机)
题意:给定一个一篇文章,然后下面有一些单词,问这些单词在这文章中出现过几次. 析:这是一个AC自动机的裸板,最后在匹配完之后再统计数目就好. 代码如下: #pragma comment(linker, ...
- cmdb客户端服务器信息采集一
#cmdb脚本程序一 #!/usr/bin/python # coding:utf-8 """ 采集机器自身信息 1 主机名 2 内存 3 ip与mac地址 4 cpu信 ...
- (一)python基础学习
根据廖雪峰老师的python教程写一些学习总结! Python基础学习 1.使用list和tuple (1)list Python内置的一种数据类型是列表:list.list是一种有序的集合,可以随时 ...
- Android上的线程安全
Thread-safe methods In some situations, the methods you implement might be called from more than one ...
- lock to deteck in oracle
0,5,10 0-23 * * * /home/oracle/utility/blocker/detect_blocker.sh db 120 > /home/oracle/utility/tr ...
- Java实现求二叉树的路径和
题: 解: 这道题考的是如何找出一个二叉树里所有的序列. 我的思路是先从根节点开始遍历,找出所有的子节点,因为每个子节点只有一个父节点,再根据每个子节点向上遍历找出所有的序列,再判断序列的总和. 这样 ...
- jqueryUI插件
<link rel="stylesheet" href="~/Content/themes/base/jquery-ui.css" /> <s ...
- volley的框架安装与使用
最后一步非常重要 不然会报错: publish = project.has("release") 替换为: publish = project.hasProperty(&q ...
- glm 矩阵乘法得反过来写
- CentOS安装使用vnc进行远程桌面登录
以下介绍在CentOS 7下安装vncserver并使用vnc-viewer进行登录(使用root权限): 1.运行命令yum install tigervnc-server安装vncserver: ...