武汉邀请赛 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 ...
随机推荐
- 一篇文章搞懂Linux安全!
Linux是开放源代码的免费正版软件,同时也是因为较之微软的Windows NT网络操作系统而言,Linux系统具有更好的稳定性.效率性和安全性. 在Internet/Intranet的大量应用中,网 ...
- Linux下安装pip(遇到了python2.6升级为python2.7道路上的坑,原因已经找到,只差临门一脚了,以后补上)
1.先说一下什么是pippip 是“A tool for installing and managing Python packages.”,也就是说pip是python的软件安装工具2.下面介绍怎么 ...
- (转)使用VS实现XML2CS
转自 StackOverFlow Method 1 XSD tool Suppose that you have your XML file in this location C:\path\to\x ...
- mysql常用日期、时间查询
好记性不如烂笔头 select curdate(); --获取当前日期 select last_day(curdate()); --获取本月最后一天. day); -- 获取本月第一天 ,interv ...
- 「雅礼集训 2018 Day10」贪玩蓝月
题目链接 题意分析 我们考虑维护两个栈 分别支持左边的插入删除以及右边的插入删除 然后对于两两个栈的我们需要用背包求出最优答案 注意 删除时如果不够的话 我们需要从另一个栈中取出一半加入另一个栈中 注 ...
- Es6 类class的关键 super、static、constructor、new.target
ES6引入了Class(类)这个概念,作为对象的模板,通过class关键字,可以定义类.基本上,ES6的class可以看作只是一个语法糖,它的绝大部分功能,ES5都可以做到,新的class写法只是让对 ...
- 2016级算法第六次上机-G.ModricWang likes geometry
1116 ModricWang likes geometry 思路 难题,非常考察几何知识,放在这里作为计算几何场次的最难的题. 原题地址 原版题解 代码
- elasticsearch 基础笔记
基础: 1.查看 所有节点,及版本 http://192.168.18.7:9200/_nodes/_all/version?pretty=true
- Zynq-7000 FreeRTOS(二)中断:串口Uart中断
总结Zynq-7000器件的PS上的串口中断,为FreeRTOS中断实验做准备.
- 使用redux-devtools工具
在vue中型项目开发的过程中,一般都是要用到vuex这个状态管理工具的,这样可以方便我们管理全局的状态,同时,为了在开发的过程中,更加方便地实时查看到state状态,我们会使用 vue-devtool ...