Simple Line Editor
来源:互联网 发布:淘宝hd怎么安装旧版本 编辑:程序博客网 时间:2024/06/17 02:12
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 ‘#’.
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
2ab#aab@aa
Sample Output
aaaa
HINT
#include<stdio.h>
#include<string.h>
int main()
{
int n,i,len,j;
char a[1000],b[1000],top,g,t;
while(scanf("%d",&n)!=EOF)
for(i=0;i<n;i++)
{
scanf("%s",a);
len=strlen(a);
top=0;
g=-1;
for(j=len-1;j>=0;j--)
if(a[j]=='@')
{
g=j;
break;
}
for(j=g+1;j<len;j++)
{
if(a[j]!='#')
{
b[top++]=a[j];
}
else
{
if(top!=0)
--top;
}
}
for(j=0;j<top;j++)
printf("%c",b[j]);
printf("\n");
}
return 0;
}
# include <stdio.h>
# include <string.h>
# define MAXN 100
char t[MAXN], s[MAXN];
int T;
int main()
{
int i, j, len;
scanf("%d", &T);
getchar();
while (T--)
{
fgets(t, MAXN, stdin);
len = strlen(t);
for (j = i = 0; i < len; ++i)
if (t[i] == '@') j = 0;
else if (t[i]=='#') j = (j>0 ? j-1:0);//这里注意要考虑j为0时
else s[j++] = t[i];
s[j] = '\0';
fputs(s, stdout);
}
return 0;
}
异曲同工。。。
- Simple Line Editor
- Simple Line Editor
- Simple Line Editor
- ACM: Simple Line Editor
- Simple Line Editor----CSU 1019
- COJ-1019-Simple Line Editor
- CSU---D: Simple Line Editor
- CSU1019-Simple Line Editor-模拟
- CSU 1019: Simple Line Editor(模拟)
- 哈理工 oj——Simple Line Editor
- Simple Editor
- simple i18n editor
- C++ HackerRank|Simple Text Editor
- On-Line Rich Text Editor.
- simple introduction for pipe line
- 为Eclipse写插件-----Simple Editor
- increase line spacing with vi editor
- simple line chart , scatter diagram and RandomWalk
- 常见的几道关于递归的JAVA面试题
- Windows平台CUDA开发之前的准备工作
- Servlet仿CSDN动态验证码的生成-带数字和字母
- Android布局大全
- CoreData是什么
- Simple Line Editor
- PHPthinking人力资源管理系统模板(源码开放)
- Maven环境配置以及Eclipse安装Maven插件
- SpringMVC学习笔记
- 超市仓库商品盘点作业流程,仓库如何进行盘点,仓库盘点流程?仓库盘点好方法?
- 导入表 与 IAT
- 怎么在程序中使用代码调用iphone打电话功能
- C预处理器和C函数库
- (转)Eclipse RCP 插件开发中经常调用的几个方法