题意:模拟文本操作

思路:模拟

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std; #define MAXN 10005
int M;
char cmd[MAXN];
char str1[MAXN],str2[MAXN];
char copyStr[MAXN]; void f(){
int i,j,k,len,len1,len2,lencp;
len=strlen(cmd);//命令长度
len1=len2=;//文本长度
lencp=;//剪贴板长度
int pos=;//光标位置
int mode=;//0 "insert mode",1 "overwrite mode"
int copyState=;//0 "NOTHING",1 "START"
int copyPosition1,copyPosition2;
for(i=;i<len;++i){
if(cmd[i]>='a'&&cmd[i]<='z'){
if(copyState==)copyState=;
if(len1<M){
if(pos==len1){
str1[len1++]=cmd[i];
str1[len1]='\0';
++pos;
}
else{
if(mode==){
for(j=k=;j<pos;++j)str2[k++]=str1[j];
str2[k++]=cmd[i];
for(j=pos;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
++len1;
++pos;
//cout<<len1<<endl;
//cout<<str1[0]<<endl;
}
else{
for(j=k=;j<pos;++j)str2[k++]=str1[j];
str2[k++]=cmd[i];
for(j=pos+;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
++pos;
}
}
}
}
else if(cmd[i]=='L'){
if(pos>)--pos;
}
else if(cmd[i]=='R'){
if(pos<len1)++pos;
}
else if(cmd[i]=='S'){
if(copyState==)copyState=;
if(mode==)mode=;//变为重写
else mode=;//变为插入
}
else if(cmd[i]=='D'){
if(copyState==){
copyState=;
copyPosition2=pos;
if(copyPosition1<copyPosition2){
for(j=k=;j<copyPosition1;++j)str2[k++]=str1[j];
for(j=copyPosition2;j<len1;++j)str2[k++]=str1[j];
str2[k++]='\0';
strcpy(str1,str2);
len1=len1-(copyPosition2-copyPosition1);
}
else{
for(j=k=;j<copyPosition2;++j)str2[k++]=str1[j];
for(j=copyPosition1;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
len1=len1-(copyPosition1-copyPosition2);
}
}
else{
if(pos<len1){
for(j=k=;j<pos;++j)str2[k++]=str1[j];
for(j=pos+;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
--len1;
}
}
}
else if(cmd[i]=='B'){
if(copyState==)copyState=;
if(pos>){
for(j=k=;j<pos-;++j)str2[k++]=str1[j];
for(j=pos;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
--len1;
--pos;
}
}
else if(cmd[i]=='C'){
if(copyState==){
copyState=;
copyPosition1=pos;
}
else{
copyState=;
copyPosition2=pos;
if(copyPosition1!=copyPosition2){
if(copyPosition1<copyPosition2){
for(j=copyPosition1,k=;j<copyPosition2;++j)
copyStr[k++]=str1[j];
copyStr[k]='\0';
lencp=copyPosition2-copyPosition1;
}
else{
for(j=copyPosition2,k=;j<copyPosition1;++j)
copyStr[k++]=str1[j];
copyStr[k]='\0';
lencp=copyPosition1-copyPosition2;
}
}
else{
memset(copyStr,'\0',sizeof(copyStr));
lencp=;
}
}
}
else if(cmd[i]=='V'){
if(lencp>){
if(mode==){
if(len1+lencp<=M){
for(j=k=;j<pos;++j)str2[k++]=str1[j];
for(j=;j<lencp;++j)str2[k++]=copyStr[j];
for(j=pos;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
len1=len1+lencp;
pos=pos+lencp;
}
}
else{
if(pos+lencp<=M){
for(j=k=;j<pos;++j)str2[k++]=str1[j];
for(j=;j<lencp;++j)str2[k++]=copyStr[j];
for(j=pos+lencp;j<len1;++j)str2[k++]=str1[j];
str2[k]='\0';
strcpy(str1,str2);
if(pos+lencp>len1)len1=pos+lencp;
pos=pos+lencp;
}
}
}
}
}
} int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&M);
//M=100;
scanf("%s",cmd);
f();
if(str1[])printf("%s\n",str1);
else printf("NOTHING\n");
}
return ;
}

hiho Mission Impossible 6(模拟 未提交验证。。)的更多相关文章

  1. MVC身份验证.MVC过滤器.MVC6关键字Task,Async.前端模拟表单验证,提交.自定义匿名集合.Edge导出到Excel.BootstrapTree树状菜单的全选和反选.bootstrap可搜索可多选可全选下拉框

    1.MVC身份验证. 有两种方式.一个是传统的所有控制器继承自定义Control,然后再里面用MVC的过滤器拦截.所以每次网站的后台被访问时.就会先走入拦截器.进行前端和后端的验证 一个是利用(MVC ...

  2. SQL Server 中的事务与事务隔离级别以及如何理解脏读, 未提交读,不可重复读和幻读产生的过程和原因

    原本打算写有关 SSIS Package 中的事务控制过程的,但是发现很多基本的概念还是需要有 SQL Server 事务和事务的隔离级别做基础铺垫.所以花了点时间,把 SQL Server 数据库中 ...

  3. ACM-ICPC国际大学生程序设计竞赛北京赛区(2015)网络赛 B Mission Impossible 6

    #1228 : Mission Impossible 6 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 You must have seen the very famou ...

  4. AngularJS系列:表单全解(表单验证,radio必选,三级联动,check绑定,form提交验证)

    一.查看$scope -->寻找Form控制变量的位置 Form控制变量 格式:form的name属性.input的name属性.$... formName.inputField.$pristi ...

  5. .NET分布式事务未提交造成6107错误或系统被挂起的问题分析定位

    问题描述: 系统中多个功能不定期出现“Unable to get error message (6107) (0).”错误,即分布式事务超时,但报出错误的部分功能根本没有使用分布式事务. 原因分析: ...

  6. Mission Impossible 6

    题目:Mission Impossible 6 题目链接:http://hihocoder.com/problemset/problem/1228 题目大意: 大概就是让我们写一个代码模拟文本编辑器的 ...

  7. SQL Server中的事务与其隔离级别之脏读, 未提交读,不可重复读和幻读

    原本打算写有关 SSIS Package 中的事务控制过程的,但是发现很多基本的概念还是需要有 SQL Server 事务和事务的隔离级别做基础铺垫.所以花了点时间,把 SQL Server 数据库中 ...

  8. 2015 ACM-ICPC国际大学生程序设计竞赛北京赛区网络赛 1002 Mission Impossible 6

    题目链接: #1228 : Mission Impossible 6 解题思路: 认真读题,细心模拟,注意细节,就没有什么咯!写这个题解就是想记录一下rope的用法,以后忘记方便复习. rope(块状 ...

  9. SVN本地代码未提交而被覆盖

    本地代码未提交而不小心被覆盖了,肿么办... 到回收站找到你的文件 xxx.mine,代码就可以找回来了.如果回收站没有了,那就没办法了. ---- 失而复得的感觉真好!

随机推荐

  1. js-判断当前页面是否在微信浏览器中打开

    方案一:推荐 var ua = navigator.userAgent.toLowerCase(); var isWinxin = ua.indexOf('micromessenger') != -1 ...

  2. [bzoj1018][SHOI2008]堵塞的交通traffic_线段树

    bzoj-1018 SHOI-2008 堵塞的交通traffic 参考博客:https://www.cnblogs.com/MashiroSky/p/5973686.html 题目大意:有一天,由于某 ...

  3. hg下拉和上传代码

    1.从代码仓库克隆源代码:$ mkdir bzrobot_ws$ cd bzrobot_ws$ hg clone http://192.168.15.88/hg/bzrobot_src src$ ca ...

  4. [Bzoj3677][Apio2014]连珠线(树形dp)

    3677: [Apio2014]连珠线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 434  Solved: 270[Submit][Status] ...

  5. java设计模式图

    一.什么是设计模式                                                                                           ...

  6. 【spring boot jpa】hql语句报错 :antlr.NoViableAltException: unexpected token: roleName

    使用场景:在spring data jpa下使用@Query("hql语句") 然后在项目启动的时候报错 hql语句报错:antlr.NoViableAltException: u ...

  7. js时间戳和时间格式之间的转换

    //时间戳转换成日期时间2014-8-8 下午11:40:20 function formatDate(ns){ return new Date(parseInt(ns) * 1000).toLoca ...

  8. BUPT复试专题—日期(2013)

    题目描述 请你计算出第年月日是第X年的第几天.其中,1月1日是第一天,1月2日是第二天,以此类推. 计算时请注意闰年的影响.对于非整百年,年数能整除4是闰年,否则不是闰年:对于整百年,年数能整除400 ...

  9. BUPT复试专题—三元组(2016)

    题目描述 给你一个长度为m的数组(数组元素从0到m-1),如果数组里有a[i]+a[j]==a[k](i,j,k大于等于0并且小于m),便称之为三元组.现在给你一个数组,让你求三元组的个数. 例如m为 ...

  10. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part1

    Despite the fact that Cypress is an application that runs natively on your machine, you can install ...