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. ...
随机推荐
- Redis学习记录
参考资料: http://www.dengshenyu.com/%E5%90%8E%E7%AB%AF%E6%8A%80%E6%9C%AF/2016/01/09/redis-reactor-patter ...
- Eclipse如何打开Android工程(转载)
转自:http://www.cnblogs.com/kernel-style/p/3339102.html 一.Eclipse如何打开Android工程 1.你可以在file->new-> ...
- mybatis基础学习5---懒加载和缓存
1:懒加载 1)在主配置文件设置(要放在配置文件最前面) 1 <!-- 延迟加载配置,两个都必须同时有 --> <settings> 3 <!-- lazyLoading ...
- sql sever使用sql语句查询数据, 分割某字段改为多行,其它字段保持不变
如表中有A.B.C三个字段,数据如下: A B C 1,2 3 4 要求查询结果: A B C 1 3 ...
- Codeforces Round #386 (Div. 2)G. New Roads [构造][树]
题目链接:G. New Roads 题意:给出n个结点,t层深度,每层有a[i]个结点,总共有k个叶子结点,构造一棵树. 分析: 考虑一颗树,如果满足每层深度上有a[i]结点,最多能有多少叶子结点 那 ...
- C# DateTime.Now 详解
//2008年4月24日 System.DateTime.Now.ToString("D"); //2008-4-24 System.DateTime.Now.ToString(& ...
- Trie树的小应用——Chemist
题意(自己编的): 给你一篇文章,包含n个长度为Si的单词,然后给你m组询问,每次询问一个单词在这篇文章中作为单词前缀出现的次数.n <=10^6,m<=10^6,Si<=100. ...
- 题解报告:hdu 1212 Big Number(大数取模+同余定理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...
- ORA-14074: partition bound must collate higher than that of the last partition
There is a error happen in crotab: CREATE parttion report ORA-14074:ORA-14074: partition bound must ...
- 等待进程结束函数中的BUG
偶然发现一个BUG,有一个函数是这样写的: void WaitProcExit(DWORD dwPid) { HANDLE hProcess = OpenProcess(PROCESS_ALL_ACC ...