武汉邀请赛 Key Logger 双向链表
Key Logger
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
Each test case contains a string L, with 1 <= Length(L) <= 1000000.
Output
Sample Input
<<o<IL>>>veU-
HelloAcmer
Sample Output
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 双向链表的更多相关文章
- bnuoj 29373 Key Logger(模拟双向队列)
http://www.bnuoj.com/bnuoj/problem_show.php?pid=29373 [题意]:模拟光标输入 [题解]:用双向列表模拟实现,这里用其他模拟会超时,注意内存的释放 ...
- logger(三)log4j2简介及其实现原理
一.log4j2简介 log4j2是log4j 1.x和logback的改进版,据说采用了一些新技术(无锁异步.等等),使得日志的吞吐量.性能比log4j 1.x提高10倍,并解决了一些死锁的bug, ...
- 动手实现一个 LRU cache
前言 LRU 是 Least Recently Used 的简写,字面意思则是最近最少使用. 通常用于缓存的淘汰策略实现,由于缓存的内存非常宝贵,所以需要根据某种规则来剔除数据保证内存不被撑满. 如常 ...
- Guava cacha 机制及源码分析
1.ehcahce 什么时候用比较好:2.问题:当有个消息的key不在guava里面的话,如果大量的消息过来,会同时请求数据库吗?还是只有一个请求数据库,其他的等待第一个把数据从DB加载到Guava中 ...
- Spring MVC之@RequestParam @RequestBody @RequestHeader 等详解
(转自:http://blog.csdn.net/walkerjong/article/details/7946109#) 引言: 接上一篇文章,对@RequestMapping进行地址映射讲解之后, ...
- redis 学习笔记(7)-cluster 客户端(jedis)代码示例
上节学习了cluster的搭建及redis-cli终端下如何操作,但是更常用的场景是在程序代码里对cluster读写,这需要redis-client对cluster模式的支持,目前spring-dat ...
- java读写Properties属性文件公用方法
Java中有个比较重要的类Properties(Java.util.Properties),主要用于读取Java的配置文件. 它提供了几个主要的方法: 1. getProperty ( String ...
- 问题--feed列表有新闻重复的问题
1. 经常有运营反应,客户端展示的feed列表有重复的问题. 重复问题分为两种,一种是两条新闻标题类似,另一种是两条新闻标题是完全相同. (1)标题类似 原来过滤的逻辑,是两个标题完全相等,才认为两条 ...
- redis3.2 Jedis java操作
package com.util; import java.util.HashSet; import java.util.List; import java.util.Map; import java ...
随机推荐
- lucene3.0_IndexSearcher排序
系列汇总: lucene3.0_基础使用及注意事项汇总 IndexSearcher排序 本文主要讲解: 1.IndexSearcher中和排序相关的方法及sort类.SortField类(api级别) ...
- Android 线刷小白教程
Android 线刷小白教程 再说一遍,绝不使用刷机精灵等软件. 一.概念 安卓系统一般把rom芯片分成7个区,如果再加上内置sd卡这个分区,就是8个: hboot分区----------负责启动. ...
- Redis存储
redis库提供了两个类:Redis和StrictRedis来实现Redis的命令操作,前者是为了兼容老版本库的集中方法,一般就用StrictRedis 一. redis基本操作 . 设置redis密 ...
- maven web不能创建src/main/java等文件等问题
我们在创建maven web项目的时候,默认只有src/main/resources这个source folder,我们按照maven结构添加src/main/java和src/test/java等s ...
- 性能测试 vs 负载测试 vs 压力测试
在做一些软件测试工作时,常常会被提及性能测试.负载测试.压力测试,这也是在软件测试方面最容易混淆的三个概念.之前和一个测试大牛聊天,他和我说常常面试一些测试人员会问一些这样的问题,大多人认为负载测试等 ...
- servlet,listener,filter,interceptor的关系
1.servlet:servlet是一种运行服务器端的java应用程序,具有独立于平台和协议的特性,并且可以动态的生成web页面,它工作在客户端请求与服务器响应的中间层.最早支持 Servlet 技术 ...
- .Net Core 发布异常 An assembly specified in the application
在Core 2.0站点发布时.. DotNet WW.kkkk.dll 报错..报文内容如下: Error: An assembly specified in the application depe ...
- springboot项目:登录 登录aop拦截 使用Redis与cookie 进行设置获取清除操作
登录.登出: 第一步:在pom文件中引入依赖 <dependency> <groupId>org.springframework.boot</groupId> &l ...
- SymbolTable
在ClassReader中有两个重要的属性,如下定义: /** A hashtable containing the encountered top-level and member classes, ...
- 介绍nodejs中的path模块的几个方法
webpack中常用的: var path = require('path') 是nodejs中的path模块,介绍一下webpack中常用的几个path模块的方法: 应用node环境的时候,这个pa ...