#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX_LEN 200100
char shuru[MAX_LEN];
typedef struct node{
char data;
struct node *next;
}Node;
typedef struct liStack{
Node *top;
}LiStack;
void initStack(LiStack *s)
{
s->top=NULL;
}
void destoryStack(LiStack *s)
{
Node *p,*q;
p=q=s->top;
free(s);
while(p!=NULL)
{
q=p->next;
free(p);
p=q;
}
free(p);
free(q);
//printf("des ok\n");
}
void push(LiStack *s,char c)
{
Node *p;
p=(Node *)malloc(sizeof(Node));
p->data=c;
p->next=s->top;
s->top=p;
//printf("push ok!\n");
}
void pop(LiStack *s,char *c)
{
Node *p;
if(s->top!=NULL)
{
p=s->top;
s->top=s->top->next;
*c=p->data;
}
}
void getTop(LiStack *s,char *c)
{
if(s->top!=NULL)
{
*c=s->top->data;
}
}
int main()
{
LiStack *t;
Node *p;
char input;
char c;
int n=0;
t=(LiStack*)malloc(sizeof(LiStack));
initStack(t);
push(t,'@');
//freopen("in.txt","r",stdin);
while(scanf("%c",&input)!=EOF)
{
if(input=='\n')
break;
if(strchr(",.?! ",input)!=NULL)
continue;
getTop(t,&c);
if(c==input)
{
pop(t,&c);
}
else
{
push(t,input);
}
}
p=t->top;
n=0;
while(p->data!='@')
{
pop(t,shuru+n);
n++;
p=p->next;
}
n--;
while(n>=0)
{
printf("%c",shuru[n]);
n--;
}
printf("\n");
destoryStack(t);
return 0;
}
1654. Cipher Message timus
最新推荐文章于 2022-02-25 19:38:17 发布