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. Android面试经历2018

    本人14年7月份出来参加工作,至今工作将近4年的时间了,坐标是深圳.由于在目前的公司,感觉没什么成长,就想换一个公司.楼主已经在从实习到现在,已经换了三家公司了,所以这次出来的目标的100人以上,B轮 ...

  2. leetcode-867-Transpose Matrix(矩阵由按行存储变成按列存储)

    题目描述: Given a matrix A, return the transpose of A. The transpose of a matrix is the matrix flipped o ...

  3. 微信内置的浏览器window.location.href 跳转不兼容问题

    1.不兼容苹果手机---->>>>使用模拟触发a标签 <a id="alink" href="http://www.baidu.com&qu ...

  4. 剑指offer——面试题29:顺时针打印矩阵

    #include"iostream" #include"stdio.h" using namespace std; void PrintMatrixInCirc ...

  5. java基本编译

    1.java语言严格区分大小写:1个源文件其中最多只能有一个public类:源文件必须和public类同名:每个类对应一个class字节码,且同名. 2.编译.   javac -d dir Hell ...

  6. Mac 10.12安装图片标注工具PxCook

    说明:现在基本是PxCook最好用,其余都是收费的,并且支持Android标注dp,主要是用于App开发时坐标定位,求到比例等等. 下载: (链接: https://pan.baidu.com/s/1 ...

  7. Mac OS 10.12使用SecureCRT 8.1.4无法保存密码的问题解决

    参考上图取消Use Keychain即可. 参考: https://jingyan.baidu.com/article/915fc414fda5fb51394b20bd.html

  8. PowerDesigner16 生成的备注脚本,在sql server 2008 中报“对象名 'sysproperties' 无效”的错误的解决办法

    主要是在建模时我们对表.列增加了些说明注释,而Sql2005之后系统表sysproperties已废弃删除而改用sys.extended_properties所致. 1.修改Table TableCo ...

  9. vue构造器以及实例属性

    一.构造器 1.vue.js就是一个构造器,通过构造器Vue来实例化一个对象:例如:var vm = new Vue({}); 2.实例化Vue时,需要传入一个参数(选项对象): 3.参数:选项对象可 ...

  10. 《LeetBook》leetcode题解(5):Longest Palindromic [M]——回文串判断

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...