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. ...
随机推荐
- 表单中的readOnly 和disabled
readonly和Disabled是用在表单中的两个属性,它们都能够做到使用户不能够更改表单域中的内容.但是它们之间有着微小的差别,总结如下: disabled也可以禁用按钮和链接: <butt ...
- Identity 使用的命名空间
必须在视图或控制器类中引用 了using Microsoft.AspNet.Identity 这个命名空间. using Microsoft.AspNet.Identity; 才能使用它User.Id ...
- UVa 1161 Objective: Berlin (最大流)
题意:给定一些航班,每个航班有人数,和起始终止时间,每次转机要花半小时,问限制时间内最多能有多少人从起始城市到终点城市. 析:差不多是裸板网络流的最大流问题,把每个航班都拆成两个点,这两个点之间连接一 ...
- ubuntu12.04向左边栏添加图标(引用)
转自:http://forum.ubuntu.com.cn/viewtopic.php?f=86&t=317442 打开想添加的软件,图标会出现在侧边栏,右击之,点Keep In Launch ...
- PHP tripos()函数使用需要注意的问题
tripos() 函数返回字符串在另一个字符串中第一次出现的位置.这在PHP字符串匹配与替换的时候常用到,但是很多时候我们总感觉当查找的字符串在源字符串的开头的时候总会不好使. 原来stripos() ...
- bzoj 1632: [Usaco2007 Feb]Lilypad Pond【bfs】
直接bfs,在过程中更新方案数即可 #include<iostream> #include<cstdio> #include<queue> using namesp ...
- P2479 [SDOI2010]捉迷藏
传送门 KDtree是个吼东西啊-- 枚举每一个点,然后求出离他距离最远和最近的点的距离,更新答案 然而为什么感觉KDtree只是因为剪枝才能跑得动呢-- //minamoto #include< ...
- _bzoj1031 [JSOI2007]字符加密Cipher【后缀数组】
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1031 保存后缀数组模版. 其实如果数据范围小一点,或者空间限制再大一点,或者甚至只要字母表再 ...
- spoj DYNALCA - Dynamic LCA
http://www.spoj.com/problems/DYNALCA/ 此题link.cut要求不能换根,当然也保证link时其中一个点必定已经是根. 方法: void link(Node *x, ...
- JavaScript的执行
下面内容参考:http://blog.csdn.net/cxiaokai/article/details/7552653 http://www.jb51.net/article/36755.htm 首 ...