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. Activity启动流程

    Activity启动过程中做了哪些事情?下面的时序图展示里启动过程中函数的调用过程, 从图中可以知道大概流程. 在介绍细节的时候是从上往下函数调用过程介绍的,如果不知道某个函数是在哪里被谁调用的,可以 ...

  2. Python 各种编码相互转化 (目前只有Unicode utf-8)

    f='\u53eb\u6211' print f print(f.decode('unicode-escape'))

  3. Linux 下的 netfilter 认识与常规操作

    Linux 下的 netfilter 认识与常规操作 前言 博客写到今天,1年7个月.可是包含所有写作经历,这个时间线可以达到三年. 上次更新了一篇 "镇站之宝" ,也是本站阅读量 ...

  4. [Virtualization] VMware虚拟机三种网络模式详解(转)

    原文:http://www.linuxidc.com/Linux/2016-09/135521.htm

  5. Nginx+SpringBoot搭建负载均衡

    v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...

  6. C语言数据结构之图的基本操作

    本博文是是博主在学习数据结构图的这一章知识时做的一些总结,代码运行环境:visual studio2017 纯C语言 ,当然掌握了方法,你也可以试着用其它的语言来实现同样的功能. 下面的程序主要实现了 ...

  7. docker 限制 容器内存 使用

    转载 : https://www.cnblogs.com/sparkdev/p/8032330.html 默认情况下容器使用的资源是不受限制的.也就是可以使用主机内核调度器所允许的最大资源.但是在容器 ...

  8. 数组或者stack

    数组 clear1(long long int array[], size_t int size) { ; i < size; i += ) array[i] = ; } li x5, // i ...

  9. Java中HashMap的hash分布策略的简单解释

    趴源码是看到一段不可思议的代码,网上的解释似乎不大令人满意,因此稍微花点时间解读了一下,如有错误请指正 HashMap的桶是这样搞的 // 片段1 static final int hash(Obje ...

  10. 思科网络设备配置AAA认证

    思科网络设备配置AAA认证登陆,登陆认证后直接进入#特权模式,下面以Cisco 3750G-24TS-S为例,其他设备配置完全是一样的,进入config terminal后命令如下: 前面是加2个不同 ...