Key Logger

Time Limit: 3000ms
Case Time Limit: 3000ms
Memory Limit: 65536KB
 
64-bit integer IO format: %lld      Java class name: Main
Font Size: + -

Decode the message from the given key logger. The logger consists:

  • ’-’ representing backspace: the character directly before the cursor position is deleted, if there is any.
  • ’<’ (and ’>’) representing the left (right) arrow: the cursor is moved 1 character to the left (right), if possible.
  • alphanumeric characters, which are part of the password, unless deleted later. Here assumes ‘insert mode’: if the cursor is not at the end of the line, and you type an alphanumeric character, then all characters after the cursor move one position to the right.
 
 

Input

The first line contains a single integer T, indicating the number of test cases.
Each test case contains a string L, with 1 <= Length(L) <= 1000000.
 

Output

For each test case, output the case number first, then the decoded message string in a line.
 

Sample Input

2
<<o<IL>>>veU-
HelloAcmer
 

Sample Output

Case 1: ILove
Case 2: HelloAcmer
 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
using namespace std; struct node
{
char c;
struct node *next;
struct node *before;
};
char a[]; int main()
{
int T,i,len,s;
while(scanf("%d",&T)>)
{ for(s=;s<=T;s++)
{
scanf("%s",a+);
len=strlen(a+);
node *head=(struct node*)malloc(sizeof(node));
head->before=NULL;
head->next=NULL;
node *p1,*p2,*p3,*p4;
p1=p2=p3=p4=head;
for(i=;i<=len;i++)
{
if(a[i]!='-' && a[i]!='>' && a[i]!='<')
{
p1=(struct node*)malloc(sizeof(node));
p1->c=a[i]; if(p2->next!=NULL)
{
p3=p2->next; p2->next=p1;
p1->before=p2;
p1->next=p3;
p3->before=p1;
p2=p1;
}
else
{
p1->next=NULL;
p1->before=p2;
p2->next=p1;
p2=p1;
}
}
else if(a[i]=='-')
{
if(p2==head) ;
else if(p2->next==NULL&&p2!=head)
{
p4=p2;
p1=p2->before;
p2=p1;
p2->next=NULL;
free(p4);
}
else
{
p4=p2;
p1=p2->before;
p3=p2->next;
p1->next=p3;
p3->before=p1;
p2=p1;
free(p4);
}
}
else if(a[i]=='<')
{
if(p2->before==NULL);
else p2=p2->before;
}
else if(a[i]=='>')
{
if(p2->next==NULL);
else p2=p2->next;
}
}
printf("Case %d: ",s);
p1=head;
while(p1->next!=NULL)
{
p4=p1;
printf("%c",p1->next->c);
p1=p1->next;
free(p4);
}
printf("\n");
}
}
return ;
}

武汉邀请赛 Key Logger 双向链表的更多相关文章

  1. bnuoj 29373 Key Logger(模拟双向队列)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=29373 [题意]:模拟光标输入 [题解]:用双向列表模拟实现,这里用其他模拟会超时,注意内存的释放 ...

  2. logger(三)log4j2简介及其实现原理

    一.log4j2简介 log4j2是log4j 1.x和logback的改进版,据说采用了一些新技术(无锁异步.等等),使得日志的吞吐量.性能比log4j 1.x提高10倍,并解决了一些死锁的bug, ...

  3. 动手实现一个 LRU cache

    前言 LRU 是 Least Recently Used 的简写,字面意思则是最近最少使用. 通常用于缓存的淘汰策略实现,由于缓存的内存非常宝贵,所以需要根据某种规则来剔除数据保证内存不被撑满. 如常 ...

  4. Guava cacha 机制及源码分析

    1.ehcahce 什么时候用比较好:2.问题:当有个消息的key不在guava里面的话,如果大量的消息过来,会同时请求数据库吗?还是只有一个请求数据库,其他的等待第一个把数据从DB加载到Guava中 ...

  5. Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解

    (转自:http://blog.csdn.net/walkerjong/article/details/7946109#) 引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后, ...

  6. redis 学习笔记(7)-cluster 客户端(jedis)代码示例

    上节学习了cluster的搭建及redis-cli终端下如何操作,但是更常用的场景是在程序代码里对cluster读写,这需要redis-client对cluster模式的支持,目前spring-dat ...

  7. java读写Properties属性文件公用方法

    Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件. 它提供了几个主要的方法: 1. getProperty ( String ...

  8. 问题--feed列表有新闻重复的问题

    1. 经常有运营反应,客户端展示的feed列表有重复的问题. 重复问题分为两种,一种是两条新闻标题类似,另一种是两条新闻标题是完全相同. (1)标题类似 原来过滤的逻辑,是两个标题完全相等,才认为两条 ...

  9. redis3.2 Jedis java操作

    package com.util; import java.util.HashSet; import java.util.List; import java.util.Map; import java ...

随机推荐

  1. verify验证插件的详解

    使用此验证插件,我们只需要新建一个实例对象,同时传入一个json对象就行了,这里我们只传入了两个属性:checkItem和callback.下面的代码解析,我们就按照这个例子来. var verify ...

  2. centos和ubuntu的网络属性配置

        一. centos的网络配置    1.  修改 /etc/sysconfig/network-scripts/ifcfg-IFACE:             DEVICE:此配置文件应用到 ...

  3. 版本控制(.git + .svn)

    git 分布式版本控制系统 底层C语言 按元数据方式存储,采用SHA-1哈希算法(内容完整性好) 结合GitHub,为开源项目免费提供Git存储 git config --global user.na ...

  4. commonjs, nodejs, npm, browserify, watchify

    CommonJS CommonJS是一套规范,定义了javascript API.其中为了解决javascript模块化的问题,引入require和export NodeJS nodeJS是服务器端j ...

  5. canvas+js画饼状图

    效果: 源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="U ...

  6. 配置不同站点不同版本PHP

    Apache 配置 1.常规手动部署apache方法(不会apache配置的请先移步看下Apache基本手工配置方法),解压fcgid,取其mod_fcgid.so至modules目录 2.打开htt ...

  7. docker + nginx 部署vuejs3.0项目

    1:用指令 npm run build 打包vusjs项目(该项目是在github上下载的).打包成功后会生成一个目录dist. 2:把该文件夹拷贝到腾讯云服务器(操作系统 centos7)下的/us ...

  8. .NET 知识点总结

    对于Web系统开发来说,Net其实也是有好多知识点需要学的,虽然目前JAVA是主流,就业市场比较大,但Net也在积极的拥抱开源,大Net Core 2 出来了,这无疑给Net开发者带来更大的希望,好了 ...

  9. centos 7 网站前端中文乱码分析、解决办法

    2019-03-28 1.网站前端中文文字乱码主要原因有两点: (1)mysql数据库内部存储的数据本身处于乱码状态 (2)前端与数据库传输数据的字符集与数据库内部字符集不一致导致 2.查找造成中文乱 ...

  10. SVN无法读取cruuent修复方法

    解决方法:在网上百度和google了一大圈之后,终于得知是断电时current和txn-current文件没有写入当前最新版本号和最新版本的路径问题 当时非常抓狂,项目刷新一直为空. 1.先把curr ...