1654. Cipher Message timus

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值