★实验任务
TonyY 是一个word 小白,今天他对 word 中撤销和恢复功能特别感兴趣,玩耍了一个上午(mdzz~),现在他知道了它们的功能和快捷键:
撤销:ctrl+z,可以撤销最近 1 次之前的恢复和 input 操作。
恢复:ctrl+y,可以恢复最近1 次之前的撤销操作,但是 input 操作之前的撤销操作不能被恢复。
当然,TonyY 还要往里写东西,操作格式为 input str(str中不含空格,str长度为m,1=<m<=30)。
现在他对 word 玩耍了起来,想知道玩耍完的结果,你可以帮助他吗?
★数据输入
输入第一行为一个正整数 n(0<=n<=10000),表示 TonyY 的操作次数。
接下来 n 行,为上述的操作之一。
其中可能有不合法操作,直接跳过即可。
★数据输出
输出 word 中的内容,字符串间用空格隔开,如果 word 为空,输出”No output”
输入示例1
4
input a
ctrl+z
ctrl+y
input b
输出示例1
a b
输入示例2
5
input a
input b
ctrl+z
input d
ctrl+y
输出示例2
a d
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct SNode*Stack;
struct SNode{
char data[10001][31];
int tag;
int top;
};
Stack Create(){
Stack S=(Stack)malloc(sizeof(struct SNode));
S->tag=-1;
S->top=-1;
}
void Push(Stack S,char *temp){
strcpy(S->data[++(S->top)],temp);
S->tag=S->top;
}
void pop(Stack S){
S->top--;
}
void peek(Stack S){
if(S->top<S->tag){
S->top++;
}
}
int main(void){
int n,i;
char str[10],temp[31];
Stack S=Create();
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%s",str);
if(strcmp(str,"input")==0){
scanf("%s",temp);
Push(S,temp);
}else if(strcmp(str,"ctrl+z")==0){
pop(S);
}else if(strcmp(str,"ctrl+y")==0){
peek(S);
}
}
int flag=0;
for(i=0;i<=S->top;i++){
if(flag) printf(" ");
else flag=1;
printf("%s",S->data[i]);
}
return 0;
}