输入格式:
输入一个字符串,长度不超过5×104,包含大小写字母、空格、下划线、{、}、<、>、#,表示贝蒂和哈利的按键序列。
输出格式:
输出为屏幕上最终显示的字符串。
输入样例1:
jlu_cc{i_love_}st
输出样例1:
i_love_jlu_ccst
#include<stdio.h>
#include<stdlib.h>
struct Queue{
char data;
struct Queue *last,*next;
}head,tail,*now;
void input(char ch);
void deleteNode();
int main()
{
head.next = &tail;
tail.last = &head;
tail.data = '\0';
now = &head;
char s[100001];
gets(s);
for(int z=0;s[z]!='\0';z++){
if(s[z]=='{') now = &head;
if(s[z]=='}') now = tail.last;
if(s[z]=='<' && now!=&head) now = now->last;
if(s[z]=='>' && now!=tail.last) now = now->next;
if(s[z]=='#') deleteNode();
input(s[z]);
}
head = *head.next;
while (head.data!='\0'){
putchar(head.data);
head = *head.next;
}
return 0;
}
void input(char ch){
if(ch=='{' || ch=='}' || ch=='<' || ch=='>' || ch=='#') return;
struct Queue *node;
node = (Queue *)malloc(sizeof(struct Queue));
node->data = ch;
node->next = now->next;
now->next->last = node;
node->last = now;
now->next = node;
now = now->next;
}
void deleteNode(){
if(now==&head) return;
struct Queue *flag = now;
now = now->last;
now->next = flag->next;
flag->next->last = now;
free(flag);
}
#include<stdio.h>
#include<stdlib.h>
struct Queue{
char data;
struct Queue *last,*next;
}head,tail,*now;
void input(char ch);
void deleteNode();
int main()
{
head.next = &tail;
tail.last = &head;
tail.data = '\0';
now = &head;
char s;
while (scanf("%c",&s) && s!='\n'){
if(s=='{') now = &head;
if(s=='}') now = tail.last;
if(s=='<' && now!=&head) now = now->last;
if(s=='>' && now!=tail.last) now = now->next;
if(s=='#') deleteNode();
input(s);
}
head = *head.next;
while (head.data!='\0'){
putchar(head.data);
head = *head.next;
}
return 0;
}
void input(char ch){
if(ch=='{' || ch=='}' || ch=='<' || ch=='>' || ch=='#') return;
struct Queue *node;
node = (struct Queue *)malloc(sizeof(struct Queue));
node->data = ch;
node->next = now->next;
now->next->last = node;
node->last = now;
now->next = node;
now = now->next;
}
void deleteNode(){
if(now==&head) return;
struct Queue *flag = now;
now = now->last;
now->next = flag->next;
flag->next->last = now;
free(flag);
}